Search code examples
javaspring-mvcaspectjspring-aop

Spring AOP - @Around Error at ::0 formal unbound in pointcut


I've looked at the other SO questions and none of them apply. Any thoughts on why @Before works, but @Around does not?

Working off the source here: http://www.captaindebug.com/2013/07/auditing-spring-mvc-webapp-with-aspectj.html#.VhUeIxNViko

This works fine:

@Before("execution(public String com.captaindebug.audit.controller.*Controller.*(..)) && @annotation(auditAnnotation)")
        public void auditScreen(JoinPoint joinPoint,Audit auditAnnotation) {...}

But this fails with the error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcContentNegotiationManager': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut

@Around("execution(public String com.captaindebug.audit.controller.*Controller.*(..)) && @annotation(auditAnnotation)")
public void profile(ProceedingJoinPoint pjp, Audit auditAnnotation) throws Throwable {...)

This also didn't work:

    @Pointcut("execution(public String com.captaindebug.audit.controller.*Controller.*(..))")
    public void controllerMethods() {}

    @Around("controllerMethods()")
    public void profile(ProceedingJoinPoint pjp) throws Throwable {}

Solution

  • @Around has to return something.

    public Object profile(ProceedingJoinPoint pjp, Audit auditAnnotation) throws Throwable {
      ...
      Object retVal = pjp.proceed();
      ...
      return retVal;
    }