Nelz's Blog

9 September 2008

Back in Action!

Filed under: Java — nelz9999 @ 20:11

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.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.