0

I have simple feignclient as shown below

@FeignClient(name="xxx")
public interface XXXServiceClient { 
   @RequestMapping(value = "/foo/bar", method = RequestMethod.POST)
   public ResponseEntity<XXX>  doSomething(@RequestBody XXX args);
}

What I want is to defined spring based pointcut and Before advice.I can define pointcut for classes with specific annotation but it does not work for feignclient interfaces.

example

@Pointcut("within(@org.springframework.stereotype.Controller *)")
public void controllerMethods() {}


@Before("controllerMethods()")
public void controllerMethodsBeforeAdvice(JoinPoint pjp) {
    System.out.println("Working");
}


@Pointcut("within(@org.springframework.cloud.netflix.feign.FeignClient *)")
public void feignClientMethods() {}


@Before("feignClientMethods()")
public void feignClientMethodsBeforeAdvice(JoinPoint pjp) {
    System.out.println("Not working");
}
murat karakas
  • 114
  • 2
  • 7
  • 1
    I am not a Spring user, rather an AspectJ expert. But I do remember that Spring AOP only works for Spring beans/components. Maybe it is because `@Controller` has a `@Component` annotation, but `@FeignClient` has not. Have you tried adding `@Component` directly to `@XXXServiceClient`? Please let me know if it works, then I can turn my comment into an answer. Otherwise please provide an [MCVE](http://stackoverflow.com/help/mcve) so as to make the problem reproducible. – kriegaex Feb 26 '18 at 12:28

1 Answers1

-2

What I was trying to do with aspect was add some custom log with my own rules. As mentioned comment above I couldn't add aop pointcut. It is possible to enable feign client logs but its format is not usable in my situation. After some research I found that it is possible to switch default http client (I used okhttp client) and add custom logger/interceptor to that client. I've prepared a small example. Another solution is that you can add custom logger to feign client, but this way is more flexible.

springboot feign logger

murat karakas
  • 114
  • 2
  • 7