方面J;当用“Before”而不是“Around”注释时调用方面

时间:2021-03-29 15:57:22

标签: java spring aop aspectj

所以我需要在从特定方法中调用方法时拦截该方法。

我有这个设置,它正在工作:

@Pointcut("execution(*com.connection.sendRequest(..))&& cflow(execution(*com.soapService.sendSoapRequest(..)))")
public void interceptSendRequestOnSoapService() {
};

@Before("interceptSendRequestOnSoapService()") 
public void interceptSoapRequest(JoinPoint point){
...
};

这很好用并且可以像我需要的那样拦截。

但是,当我将注释更改为“Around”时:

@Around("interceptSendRequestOnSoapService()") 
public void interceptSoapRequest(JoinPoint point){
...
};

它根本没有被调用。它甚至从未进入方面。它不会拦截。为什么,我怎样才能让它在@Around 上工作?

1 个答案:

答案 0 :(得分:0)

好吧,我似乎已经想通了。

  1. 我将第一次执行更改为“调用”。所以调用(* com.connection.sendRequest(..))

  2. 我让我的方法返回一个对象。所以“返回joinpoint.proceed()”

相关问题