【问题标题】:@target pointcut throws IllegalStateException@target 切入点抛出 IllegalStateException
【发布时间】:2020-08-08 11:06:34
【问题描述】:

在 Spring boot AOP 应用程序中,我有一个切入点 @target(MyAnnotation) || @annotation(MyAnnotation)。 如果将 MyAnnotation 放在执行带有此注解的对象或注解的方法上,则应执行建议。

当我运行应用程序时,我得到

java.lang.IllegalArgumentException: Cannot subclass final class org.springframework.cloud.sleuth.log.Slf4jScopeDecorator

here 讨论了一个类似的问题,但似乎切入点太宽,我的不是因为我在项目中只有几个带有 MyAnnotation 的注释类。

我把这个注解放到feign客户端界面上,像这样。

@MyAnnotation
@FeignClient(name="some-name", url="http://test.url")
public interface MyClient {
    @RequestMapping(method = RequestMethod.GET, value = "/endpoint")
    List<Store> getSomething();
}

任何想法我的切入点有什么问题?

【问题讨论】:

    标签: aop spring-aop pointcut


    【解决方案1】:

    好的,经过数小时的调查,我用这个替换了我的切入点

    @Around("execution(* (@MyAnnotation *).*(..)) || execution(@MyAnnotation * *(..))")
    

    正如here 解释的那样,我只使用execution 来避免创建代理。希望这会有所帮助

    【讨论】:

    • 嘿,居然有人在SO上使用搜索功能,哇!我希望更多的人会这样做。我很高兴我的旧答案对您有所帮助。 ;-)
    猜你喜欢
    • 2019-06-10
    • 2015-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    相关资源
    最近更新 更多