Spring aop方面不触发



我有一个弹簧组件,我需要检查一个方法:

String methodA(String param) {
...//do something 
}

现在我创建了一个方面来捕捉方法的执行:

@Aspect
@Component
@ConditionalOnProperty(name = "is.enabled", matchIfMissing = true)
public class LoggingAspect {

@AfterReturning(pointcut = "execution(* com.A.methodA(..))", returning = "result")
void logMethodA(String result) {
...//do something with result
}

In properties标志设置为true以触发方面

is.enabled=true

也尝试了execution(* com.A.methodA(String)),没有变化。从工作方面复制方法,被触发,找不到线索。

您应该检查您的LoggingAspect是否在Spring上下文中注册为bean。尝试移除或更改@ConditionalOnProperty@ConditionalOnProperty(value = "is.enabled", havingValue = true, matchIfMissing = true)

最新更新