Spring AOP @AfterThrowing无法正常工作,错误在:: 0正式未绑定切入点

时间:2017-11-29 09:51:53

标签: java spring spring-aop

我正在定义@pointcut表达式,如下所示。

@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);
     }

它返回错误说:

 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 

如果我删除@AfterThrowing,上面的代码就可以了,所以现在问题出在@AfterThrowing上。

我从shared\lib

中删除了aspectjrt-1.6 jar后,问题得到了解决

1 个答案:

答案 0 :(得分:1)

您需要在Throwable e中绑定@AfterThrowing参数。使用注释的throwing属性:

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