V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
whajcf
V2EX  ›  Java

请教~ AOP 拦截不到 controller 接口

  •  
  •   whajcf · Sep 22, 2020 · 3537 views
    This topic created in 2046 days ago, the information mentioned may be changed or developed.
    项目环境是 SpringBoot+Jersey 接口通过 @Component 集成, 使用 aop 去拦截接口 controller 无法成功,拦截 controller 调用的 service 没有问题, 网上的解决方法大部分已经尝试没有拦截成功,请指点如何进行切片?
    6 replies    2020-09-23 13:55:32 +08:00
    feidao158
        1
    feidao158  
       Sep 22, 2020
    啥都没有怎么给你解答
    zacone
        2
    zacone  
       Sep 22, 2020
    Spring AOP 只能拦截`interface `类的实现方法。
    controller 层的类一般不会实现`interface`,所以无法拦截; service 层一般都会写`interface `类加对应实现类这样方便拓展,所以拦截没有问题
    wangshicheng
        3
    wangshicheng  
       Sep 22, 2020
    配置文件加 AOP 的配置了吗
    limuyan44
        4
    limuyan44  
       Sep 22, 2020
    我算了一卦你没写 @Aspect,至于说拦截不了接口的,不存在的。
    RedBeanIce
        5
    RedBeanIce  
       Sep 23, 2020
    贴代码,看你引入的包,只要是引入的 spring-boot-starter-aop
    无物不可切
    whajcf
        6
    whajcf  
    OP
       Sep 23, 2020
    已经放弃 框架问题 框架 jersey 使用自己的 Filter 单独整理接口业务代码放入 service 进行切片处理 老项目维护害人不浅
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5100 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 52ms · UTC 09:06 · PVG 17:06 · LAX 02:06 · JFK 05:06
    ♥ Do have faith in what you're doing.