1. 学习用feign 时,一开始用@GetMapping 注解还可远程调用,没有问题
在当用@PathVariable传路径变量时,服务总报500.
百度发现 @PathVariable时,@RequestMapping不能用GetMapping直接替换,必须用对其value参数直接赋值才可用。正确如下:
@FeignClient(value = "test")
public interface IFeignTestService {
// if PathVariable is used, it is forbidden to use @GetMapping to replace @RequestMapping;
@RequestMapping(value = "/test/ribbon/test/{id}", method = RequestMethod.GET)
public Object getTest(@PathVariable("id") String id);
}
2. 使用Feign 自定义配置时,为防止 @Configuration 被当成@Component加载,以致对所有@FeignClient 生效。
当用@ComponentScan 显示加载指定包,排除FeignConguration。
对@FeignClient的想要使用指定自定义配置的,可用conguration属性来指定
3. Feign 调用接口的日志
日志级别枚举类Logger.Level
NONE:不输出日志
BASIC:输出请求方法、URL、响应状态码、执行时间
HEADERS:基本信息以及请求和响应头
FULL:请求和响应的heads、body、metadata,建议使用这个级别
注:1. Feign的Level日志级别配置默认是:NONE,不要跟log日志混淆。
2. feign 日志的 log日志级别为DEBUG.
/**
-
if this configuration is scanned by the @ComponentScan, it will take effects on all the FeignClients.
-
Therefore, we use IgnoreComponentScan to avoid this configuration’s being scanned so that it can work
-
the specific Feign clients with annotation @FeignClient taking FeignConfiguration.class as the value of
-
its attribute configuration.
*/
@Configuration
@IgnoreComponentScan
public class FeignConfiguration {/**
- set feign log level basic, this need the debug level of
- the logger(for example logback)to print the feign logs.
- @return
*/
@Bean
Logger.Level feignLoggerLevel() {
return Logger.Level.BASIC;
}
}