代码结构:

spring aop execution用法

1、

"execution(*  com.ebc..*.*(..))"  与 "execution(*  com.ebc..*(..))"

2019-01-29 09:38:28.230 [5c4fae94cbb0aa9e2110d155] INFO | c.e.w.IndexController.index:23 - controller接收:遥远2
2019-01-29 09:38:28.237 [5c4fae94cbb0aa9e2110d156] INFO | c.e.s.IndexService.doIndex:11 - service接收:遥远2

2、

@Pointcut("execution(*  com.ebc.web.*.*(..))") 与@Pointcut("execution(*  com.ebc.web.IndexController.*(..))")【本例是相同的】

2019-01-29 09:48:37.152 [5c4fb0f5cbb09a4ade3280b6] INFO | c.e.w.IndexController.index:23 - controller接收:遥远2
2019-01-29 09:48:37.152 [5c4fb0f5cbb09a4ade3280b6] INFO | c.e.s.IndexService.doIndex:11 - service接收:遥远2

3、

@Pointcut("@within(org.springframework.stereotype.Controller) || @within(org.springframework.web.bind.annotation.RestController)")

2019-01-29 09:51:26.951 [5c4fb19ecbb01db5f6fd96b9] INFO | c.e.w.IndexController.index:23 - controller接收:遥远2
2019-01-29 09:51:26.952 [5c4fb19ecbb01db5f6fd96b9] INFO | c.e.s.IndexService.doIndex:11 - service接收:遥远2

 

注意:如果使用aop做MDC日志,切入点只能在入口类。否则,每个类输出的都是不同的数值。

 

相关文章:

  • 2021-11-18
  • 2022-02-24
  • 2022-12-23
  • 2021-10-13
  • 2021-07-27
  • 2021-12-12
猜你喜欢
  • 2021-06-03
  • 2021-08-10
  • 2022-12-23
  • 2021-06-26
  • 2021-06-23
相关资源
相似解决方案