Md Faisal
Md Faisal

Reputation: 2991

Spring AOP @AfterThrowing not working properly, error at ::0 formal unbound in pointcut

I am defining the @pointcut expression like below.

@Pointcut(
        "execution(* com.xyz..*(..)) && " +
        "!within(is(EnumType)) && " +
        "!within(is(FinalType))"
    )
protected void loggingOperation() {

}
@Before("loggingOperation()")
    public void logEntry1(final JoinPoint joinPoint) {

        logger.log(Level.INFO, "Entering " + joinPoint.getTarget().getClass().getName() + " ##### "
                + joinPoint.getSignature().getName(), joinPoint.getArgs());
    }

    @After("loggingOperation()")
    public void logExit1(final JoinPoint joinPoint) {
        logger.log(Level.INFO, "Exiting " + joinPoint.getTarget().getClass().getName() + " ##### "
                + joinPoint.getSignature().getName(), joinPoint.getArgs());

    }

     @AfterThrowing("loggingOperation()")
     public void logException1(JoinPoint joinPoint, Throwable e) {
     logger.log(Level.SEVERE,
     joinPoint.getTarget().getClass().getName() + " ##### " +
     joinPoint.getSignature().getName(), e);
     }

it returns error saying:

 Error creating bean with name 'resourceDataSource' defined in class path resource [resource-dataSource-dbcp-beans.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at 

The above code works fine if I remove @AfterThrowing so now the problem is with @AfterThrowing.

The earlier problem got solved after I removed aspectjrt-1.6 jar from shared\lib

Upvotes: 0

Views: 1395

Answers (1)

Michał Grzejszczak
Michał Grzejszczak

Reputation: 2617

You need to bind Throwable e parameter in @AfterThrowing. Use throwing attribute of the annotation:

@AfterThrowing(pointcut = "loggingOperation()", throwing = "e")
public void logException1(JoinPoint joinPoint, Throwable e) {
  ...
}

Upvotes: 1

Related Questions