I'm trying to use Spring AOP to intercept Feign.Client
calls and log request and response to my Splunk Server. All methods in my project package are intercepted as I expected but Feign.Client
doesn't.
This is my AOP class:
@Component
@Aspect
public class MyAspect {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Pointcut("execution(* com.example.demo.*.*(..))")
public void pointCutDemo(){}
@Pointcut("execution(* feign.Client+.*(..))")
public void pointCutFeign(){}
@Around("pointCutDemo()")
public void myAroundDemo(ProceedingJoinPoint joinPoint) throws Throwable {
logger.info("calling joinpoint "+joinPoint.getSignature().getName());
joinPoint.proceed();
}
@Around("pointCutFeign()")
public void myAroundFeign(ProceedingJoinPoint joinPoint) throws Throwable {
logger.info("calling feign joinpoint "+joinPoint.getSignature().getName());
joinPoint.proceed();
}
}
The method myAroundDemo
is called multiple times, as I expected, but myAroundFeign
is never called.
I have a simple Controller that call my interface (Feign API), this is the controller:
@RestController
public class Controller {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private ExternalAPI externalAPI;
@GetMapping
public String get(){
logger.info("calling get method");
logger.info(String.valueOf(externalAPI.listUsers()));
return "I'm here";
}
}
And this is my Feign Interface:
@FeignClient(url = "http://localhost:3000", name = "feign", configuration = FeignConfig.class)
public interface ExternalAPI {
@GetMapping(value = "/menu")
String listUsers();
}