【发布时间】:2019-06-20 22:01:29
【问题描述】:
我正在尝试使用 Spring AOP 拦截 Feign.Client 调用并记录对我的 Splunk 服务器的请求和响应。我的项目包中的所有方法都按我的预期被拦截,但Feign.Client 没有。
这是我的 AOP 类:
@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();
}
}
正如我所料,方法myAroundDemo 被多次调用,但从未调用myAroundFeign。
我有一个简单的控制器来调用我的接口(Feign API),这是控制器:
@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";
}
}
这是我的 Feign 界面:
@FeignClient(url = "http://localhost:3000", name = "feign", configuration = FeignConfig.class)
public interface ExternalAPI {
@GetMapping(value = "/menu")
String listUsers();
}
【问题讨论】:
标签: aop spring-aop spring-cloud-feign feign