我正在学习春季的AOP概念。我现在非常清楚@Before和@After注释的用法,并开始使用它来捕捉时间。
这基本上满足了我所有与AOP相关的需求。想知道每个春季指南都在谈论什么@pointcut注释吗?这是多余的功能吗?还是有不同的需求?
发布于 2017-05-08 09:31:48
简单地说,您在“前”或“后”中指定的任何内容都是切入点表达式。为了更好地理解、模块化和更好的控制,可以使用@Pointcut注释将其提取到单独的方法中。例如
@Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
public void requestMapping() {}
@Pointcut("within(blah.blah.controller.*) || within(blah.blah.aspect.*)")
public void myController() {}
@Around("requestMapping() && myController()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
...............
} 如您所见,您可以使用@Around将其分隔为两个方法,而不是在@Pointcut中指定切入点表达式。
https://stackoverflow.com/questions/43844096
复制相似问题