In a Spring Boot project I have a simple feign client
@MyAnnotation
@FeignClient(name="some-name", url="http://test.url")
public interface MyClient {
@RequestMapping(method = RequestMethod.GET, value = "/endpoint")
List<Store> getSomething();
}
I need to intercept all calls and for this and I'm creating a common library that can be used in different projects. To achieve it I try to use Spring AOP. I created an aspect that wraps all public methods of the object annotated with MyAnnotation
@Around("@within(MyAnnotation) && execution(public * *(..))")
public Object myWrapper(ProceedingJoinPoint invocation) throws Throwable {
// ...
}
It works correctly and all calls are intercepted till I tried to put MyAnnotation
on the feign client that uses inheritance for feign interfaces. When I init my client with inherited interface calls are not intercepted anymore.
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{
}
I tried:
"@target(MyAnnotation) && execution(public * *(..))"
but when I connected my library to the real project I got java.lang.IllegalArgumentException: Cannot subclass final class org.springframework.boot.autoconfigure.AutoConfigurationPackages$BasePackages
It seems that it wanted to wrap all to the proxy and there were final classes."@target(MyAnnotation) && execution(public * com.my.company.base.package.*(..))"
removed previous issue but gave another one, like some bean cannot be instantiated without name, etc. The question is how to make it work without moving @MyAnnotation
to the base interface FeignClientInterface
. It is in another project and I don't have a control on it.
Ok, after hours of investigation I replaced my pointcut with this one
@Around("execution(* (@MyAnnotation *).*(..)) || execution(@MyAnnotation * *(..))")
As explained here I used only execution
to avoid proxy creation.