Serge Serge - 1 year ago 91
Java Question

Aspectj doesn't catch all events in spring framework?

My project is based on spring framework 2.5.4. And I try to add aspects for some controllers (I use aspectj 1.5.3).

I've enabled auto-proxy in application-servlet.xml, just pasted these lines to the end of the xml file:

<aop:aspectj-autoproxy />
<bean id="auditLogProcessor" class="" />

Created aspect:


import org.apache.log4j.Logger;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

public class AuditLogProcessor
private final static Logger log = Logger.getLogger(AuditLogProcessor.class);

public void afterHandleRequest() {"test111");

public void afterRebuildThumbnail() {"test222");

My controllers:

class AssetAddController implements Controller
class AssetThumbnailRebuildController extends MultiActionController

When I set brake points in aspect advisors and invoke controllers I catch only afterHandleRequest() but not afterRebildThumbnail()
What did I do wrong?


I'm asking this question on behalf of my friend who doesn't have access to SO beta, and I don't have a clue what it's all about.


There were indeed some misspellings, thanks Cheekysoft. But the problem still persists.

Answer Source

Your breakpoints aren't being hit because you are using Spring's AOP Proxies. See understanding-aop-proxies for a description of how AOP Proxies are special.

Basically, the MVC framework is going to call the handleRequest method on your controller's proxy (which for example the MultiActionController you're using as a base class implements), this method will then make an "internal" call to its rebuildThumbnail method, but this won't go through the proxy and thus won't pick up any aspects. (This has nothing to do with the methods being final.)

To achieve what you want, investigate using "real" AOP via load time weaving (which Spring supports very nicely).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download