javaspringspring-aopspring-cloud-feignpointcut

How to create pointcut to feign client that supports interface inheritance?


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:

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.


Solution

  • 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.