Nelz's Blog

Mah blogginess

Back in Action!

I am now back from Burning Man, and having a fairly smooth re-adjustment to this so called real world.

Spring AOP and Internal Method Calls

When using AspectJ with Spring’s AOP framework, I didn’t realize that there were challenges getting AOP to work when a member method calls to a sibling method.

Here’s an example I’ve borrowed from some discussion of this phenomenon:

public class MyService {
public methodA()
{
//do something
methodB();
//do something
}
public methodB()
{
//do something else
}
}

Now both the method in the service have been AOPed, and when I call the methodA() on the proxied instance, the methodA() will have the benefit of the aspect, but when the methodB() gets called from methodA(), it would not get that benefit of AOP.

Used strategically, I think this can be a benefit. When I came upon this problem, I basically used it as an opportunity to refactor "methodB" (and it’s associated overhead) into a new stand-alone class. This may not always solve your specific problem, but it worked in my one case so far.