由网友(初见.)分享简介:在一个Spring Boot项目中,我有一个简单的假客户端@MyAnnotation@FeignClient(name="some-name", url="http://test.url")public interface MyClient {@RequestMapping(method = RequestMeth...![用蛤蟆连细胞分裂5局域网提示没有找到比赛](https://p.xsw88.cn/allimgs/daicuo/20230904/6793.png)
在一个Spring Boot项目中,我有一个简单的假客户端
@MyAnnotation
@FeignClient(name="some-name", url="http://test.url")
public interface MyClient {
@RequestMapping(method = RequestMethod.GET, value = "/endpoint")
List<Store> getSomething();
}
我需要拦截所有调用,为此,我正在创建一个可在不同项目中使用的公共库。为了实现它,我尝试使用了Spring AOP。我创建了一个方面,它包装了用MyAnnotation
@Around("@within(MyAnnotation) && execution(public * *(..))")
public Object myWrapper(ProceedingJoinPoint invocation) throws Throwable {
// ...
}
它工作正常,所有调用都会被截获,直到我尝试将MyAnnotation
放在使用feign接口继承的feign客户端上。当我使用继承的接口调用初始化我的客户端时,不再被拦截。
public interface FeignClientInterface {
@RequestMapping(method = RequestMethod.GET, value = "/endpoint")
List<Store> getSomething();
}
@MyAnnotation
@FeignClient(name="some-name", url="http://test.url")
public interface MyClient extends FeignClientInterface{
}
![用蛤蟆连细胞分裂5局域网提示没有找到比赛](https://p.xsw88.cn/allimgs/daicuo/20230904/6793.png)
我已尝试:
"@target(MyAnnotation) && execution(public * *(..))"
但当我将我的库连接到实际项目时,我得到了java.lang.IllegalArgumentException: Cannot subclass final class org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages
,它似乎想要将所有内容包装到代理,并且有最终的类。
"@target(MyAnnotation) && execution(public * com.my.company.base.package.*(..))"
删除了上一个问题,但给出了另一个问题,如某些Bean没有名称无法实例化等。
问题是如何在不将@MyAnnotation
移动到基本接口FeignClientInterface
的情况下使其工作。它在另一个项目中,我无法控制它。
推荐答案
好的,经过几个小时的调查,我用这个替换了我的切入点
@Around("execution(* (@MyAnnotation *).*(..)) || execution(@MyAnnotation * *(..))")
如前所述here我使用execution
只是为了避免创建代理。
相关推荐
最新文章