October 13, 2007

AspectJ aspect configured by Spring

Filed under: Java,JEE — khangharoth @ 9:34 am

Today i came across a peculiar problem and more importantly it hit me in my face ,the integration tests were breaking and result of this were mail’s flying all across.

We are having a Web-Service which web-client calls and in the server side we are using spring as application framework.We were using aspect of AspectJ for some purpose and it needed certain properties which were available in spring.xml,so we thought to configure the aspect from spring.

Now just to quote a citation

Now I’d like to configure my aspect with a particular exception handling strategy using dependency injection. For this, I can use the standard Spring approach, but with one caveat. Normally Spring is responsible for both creating and configuring beans. AspectJ aspects, however, are created by the AspectJ runtime. I need Spring to configure the aspect that AspectJ has created. For the most common case of singleton aspects such as the RemoteExceptionHandling aspect above, AspectJ defines an aspectOf() method that returns the aspect instance. I can tell Spring to use the aspectOf() method as a factory method for obtaining the aspect instance. Listing 2 shows the Spring configuration for the aspect:

Now what i mistakenly did was put this line of code in my spring.xml.

And everything was fine in Unit-testing and functional level testing.But as soon as client tried to generate the proxies from WSDL,their were number of proxies getting generated which were not even part of our WS interface.

After debugging , i got the cause of  those extra classes in WS interface.As sprin AOP is proxy based framework and it was this that was creating those extra proxy classes.

Need to get more into Spring AOP and how it is different from AspectJ.


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: Logo

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

Google+ photo

You are commenting using your Google+ 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

Create a free website or blog at

%d bloggers like this: