Java Spring AOP@AfterThrough无法正常工作,切入点中的::0正式解除绑定处出错
我正在定义@pointcut表达式,如下所示Java Spring AOP@AfterThrough无法正常工作,切入点中的::0正式解除绑定处出错,java,spring,spring-aop,Java,Spring,Spring Aop,我正在定义@pointcut表达式,如下所示 @Pointcut( "execution(* com.xyz..*(..)) && " + "!within(is(EnumType)) && " + "!within(is(FinalType))" ) protected void loggingOperation() { } @Before("loggingOperation()") public
@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
如果我删除@Afterhrowing,上面的代码可以正常工作,所以现在问题是@Afterhrowing
在我从shared\lib中删除aspectjrt-1.6jar之后,前面的问题得到了解决。您需要在@afterhrowing中绑定Throwable e参数。使用注释的属性:
@AfterThrowing(pointcut = "loggingOperation()", throwing = "e")
public void logException1(JoinPoint joinPoint, Throwable e) {
...
}
我怀疑AspectJ不支持*def。我想您应该为包com.xyz或子包中以def结尾的类的任何公共方法startProcess创建切入点。尝试将其分离为较小的PointCuit,正如预期的那样,它在@Before和@After中工作。当您在pointcut方法中有一个参数时,就会在pointcut中正式解除绑定。您应该使用args在切入点中绑定它,例如:execution*method..&&argsparam1。但是,您的示例没有显示任何参数。您确定发布的是有问题的切入点定义,而不是其他正确的定义吗?最后一个例子应该是:执行…&&在",在内部我不明白的是,同一个表达式在@Before和@After中都起作用,如果一个表达式写得不好,它就不应该起作用。在上一个例子中,我只是尝试了在SO上找到的一个解决方案,只是想看看它是否有效。它在我的环境中工作得很好。