作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Spring 中学习 AOP 概念。我现在很清楚 @Before
的用法和 @After
注释并开始将其用于时间捕获目的。
这几乎满足了我所有与 AOP 相关的需求。想知道那是什么@pointcut
每个 Spring 指南都在谈论的注释?那是多余的功能吗?还是有单独的需求?
最佳答案
简单来说,您在 @Before 或 @After 中指定的任何内容都是切入点表达式。可以使用 @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
将其分为两种方法.
关于spring - 何时使用@Pointcut & @Before、@After AOP 注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43844096/
我是一名优秀的程序员,十分优秀!