Take the 2-minute tour ×

I've been working on adding aspects to a Spring MVC webapp, and the aspects aren't executing. I've tried to boil it down to something dirt simple that clearly should work, but still no go. Here's where I'm at now:

// imports...
public class AuthCheckerAspect {

    @Pointcut("execution(* * *(..))")
    public void c() {}

    public void cc(JoinPoint pjp) throws Throwable {

As far as I can tell, the pointcut should apply to any method in any Spring-managed class (of which there are a lot in my application). I also added the following to my Spring config:


I set a breakpoint at the System.out.println() statement in the cc() method, but it never caught (and yes, I'm positive that the debugger is attached; other breakpoints catch properly). I'm suspecting that the AuthCheckerAspect class is never getting loaded into the Spring context, because I also set a breakpoint within the initializer clause, and that never catches either; when I do the same with other Spring-managed classes, their breakpoints always catch during app startup.

Is there something else I need to be doing?

Thanks in advance.

share|improve this question
How do you invoke the method that is extended by the aspect. From the same bean (like this.otherMethod()) or from an other bean (like: otherBean.otherMethod())? –  Ralph Nov 17 '11 at 9:05
Hey Ralph, if you're asking about the method(s) to which the aspect would be applied, then they would be invoked by other Spring-managed beans. –  Dave Taubler Nov 17 '11 at 21:10
Ok, the problem seams solved. –  Ralph Nov 18 '11 at 6:40

2 Answers 2

up vote 7 down vote accepted

Spring does not automatically mange @Aspects. Add <bean class="AuthCheckerAspect" /> to your context or annotate it with @Component and include in component scan path.

share|improve this answer
Thanks. I tried each, but each time the whole app just failed to start up altogether. I'll try to figure out why... –  Dave Taubler Nov 17 '11 at 7:05
Hmm... java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting '(' at character position 0. At any rate, you seemed to have gotten me past one hurdle, so +1. –  Dave Taubler Nov 17 '11 at 7:24
Look here(static.springsource.org/spring/docs/3.0.x/…) for pointcut syntax examples. –  madhead Nov 17 '11 at 7:36
Thanks. I'm positive something else is the real problem, as I've been pasting in pointcuts that I'm successfully using in other parts of the app (e.g. for transaction management). It's very weird... –  Dave Taubler Nov 17 '11 at 15:29
Ah-ha, I solved that last problem! The error was a tiny bit misleading; it seems it wasn't my pointcut that was bad, but rather the advice. @Before("c") should have contained parentheses, like @Before("c()") –  Dave Taubler Nov 17 '11 at 21:12

add this to your configuration file:

<context:annotation-config />
<context:component-scan base-package="root.package.to.be.scanned" />
    <aop:include name="nameOfAspectBean" />
share|improve this answer

Your Answer


