V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wangsilence
V2EX  ›  程序员

Spring Cache、Async AOP 实现疑问

  •  
  •   wangsilence · 2021-01-14 16:00:38 +08:00 · 950 次点击
    这是一个创建于 1169 天前的主题,其中的信息可能已经有所发展或是发生改变。

    为什么 Spring Cache 、Async AOP 实现都自己实现了 Advisor 、Advice 、Pointcut, 为什么不直接用 @Aspect 表达式,直接拦截注解,剩了很多代码,Advisor 、Pointcut 都不用写。 更简单的方式不用,为什么要这么复杂实现?

    @Aspect
    @Component
    public class Aspect {
    
        @Pointcut("@annotation(com.xxx.Cache)")
        public void pointcut() {
        }
    
        @Around(value = "pointcut() && @annotation(cache)")
        public Object imMonitorAround(ProceedingJoinPoint pjp, Cache cache) throws Throwable {
            String methodKey = imMonitor.value();
            return pjp.proceed();
        }
    }
    
    1 条回复    2021-01-15 09:23:21 +08:00
    ychost
        1
    ychost  
       2021-01-15 09:23:21 +08:00
    Aspect 表达式必须强制要求启动的时候指定 Aspect 的 Processor 吧
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3116 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:30 · PVG 22:30 · LAX 07:30 · JFK 10:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.