我正在定义@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
答案 0 :(得分:1)
您需要在Throwable e
中绑定@AfterThrowing
参数。使用注释的throwing
属性:
@AfterThrowing(pointcut = "loggingOperation()", throwing = "e")
public void logException1(JoinPoint joinPoint, Throwable e) {
...
}