gpt4 book ai didi

java - Spring AOP @AfterThrowing 无法正常工作,错误于::0 切入点中正式未绑定(bind)

转载 作者:行者123 更新时间:2023-12-02 11:56:50 26 4
gpt4 key购买 nike

我正在定义 @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后,早期的问题得到了解决

最佳答案

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

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

关于java - Spring AOP @AfterThrowing 无法正常工作,错误于::0 切入点中正式未绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47549746/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com