You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# AOP
spring.aop.auto=true # Add @EnableAspectJAutoProxy.
spring.aop.proxy-target-class=false # Whether subclass-based (CGLIB) proxies are to be created (true) as opposed to standard Java interface-based proxies (false).
Around--目标方法调用之前执行
2017-07-03 17:33:15.494 INFO 8548 --- [nio-8443-exec-7] tConfig$$EnhancerBySpringCGLIB$$5f4562fb : requset method name is: testAOP
2017-07-03 17:33:15.495 INFO 8548 --- [nio-8443-exec-7] tConfig$$EnhancerBySpringCGLIB$$5f4562fb : request URL is: https://localhost:8443/aop
2017-07-03 17:33:15.495 INFO 8548 --- [nio-8443-exec-7] tConfig$$EnhancerBySpringCGLIB$$5f4562fb : request http method: GET
2017-07-03 17:33:15.495 INFO 8548 --- [nio-8443-exec-7] tConfig$$EnhancerBySpringCGLIB$$5f4562fb : request arguments are: []
Before--通知方法会在目标方法调用之前执行
Around--目标方法返回后调用
After--通知方法会在目标方法返回或抛出异常后调用
AfterReturning--通知方法会在目标方法返回后调用; retVal = this is a AOP test. (@Around can change the return value!) (@AfterReturning can read the return value, but it can't change the value!)
execution(public java.lang.String com.ansel.testall.aop.AOPController.testAOP())
页面返回结果如下: this is a AOP test. (@Around can change the return value!)
触发 localhost:8080/aop/introdution 请求,控制台输出结果如下:
注:
@Pointcut("execution(* com.ansel.testall.aop..*(..)) and @annotation(org.springframework.web.bind.annotation.RestController)")
/**
* OK
*/
@Pointcut("execution(* com.ansel.testall.aop..*(..)) and @annotation(org.springframework.web.bind.annotation.RestController)")
/**
* not OK
*/
@Pointcut("execution(* com.ansel.testall.aop..*(..)) && @annotation(org.springframework.web.bind.annotation.RestController)")
/**
* OK
*/
@Pointcut("execution(* com.ansel.testall.aop..*(..)) and @annotation(org.springframework.web.bind.annotation.RequestMapping)")
/**
* OK
*/
@Pointcut("execution(* com.ansel.testall.aop..*(..)) && @annotation(org.springframework.web.bind.annotation.RequestMapping)")
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
页面返回结果如下:
this is a AOP test. (@Around can change the return value!)
触发 localhost:8080/aop/introdution 请求,控制台输出结果如下:
注:
@Pointcut("execution(* com.ansel.testall.aop..*(..)) and @annotation(org.springframework.web.bind.annotation.RestController)")
当我使用and操作符连接上面两个切点指示器,没有任何问题(把注解RestController换成RequestMapping也没问题)
然而,当我使用&&操作符连接上面两个切点指示器时,完全没有触发AspectJ,切面没有织入任何连接点(把注解RestController换成RequestMapping就没问题)
The text was updated successfully, but these errors were encountered: