I have a Spring project uses annotations to apply (among other things) caching.
My understanding is that these annotations will only work when @Autowired and called through SpringAOP.
This means that if a method calls another in the same class, then any annotations on the second method are ignored e.g.
@Cacheable(...)
public Animal getAnimal(int id) {
return get(m_url, id);
}
public Cage getCagedAnimal(int id) {
Animal animal = getAnimal(id); // This call will not apply @Cacheable
Cage cagedAnimal = new Cage(animal);
return cagedAnimal;
}
What I am looking for is a way to enforce against this i.e. public methods should not be able to call other public methods of the same class.
I tried applying something similar to the approach used here http://www.jayway.com/2010/03/28/architectural-enforcement-with-aid-of-aspectj but it falls short when applying the restriction on the same class.