今天在开发过程中,遇到一个问题卡了很久,测试代码如下:
package spring.pointcut; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; /** * @Description: Pointcut测试 * @Author: qionghui.fang * @Date: 2018/10/23 上午10:10 */ @Aspect public class TargetMonitor { // 配置方法1 // @Pointcut("execution(* spring.pointcut.Target.onEvent(String))") // private void anyMethod() {} // @Around("anyMethod()") //配置方法2 @Around("execution(* spring.pointcut.Target.onEvent(..))") public Object monitor(ProceedingJoinPoint point) throws Throwable { System.out.println("before"); try { return point.proceed(); } finally { System.out.println("after"); } } }
目标类:
public class Target { public void otherEvent(){ System.out.println("Call otherEvent()"); } public boolean onEvent(Integer type, Long Value){ System.out.println("Call onEvent(Integer type, Long Value)"); for (int i=0; i<=3; i++){ onEvent(""); } System.out.println("End Call onEvent(Integer type, Long Value)"); return true;