Fegin 单客户端配置类方式设置配置
个人所知的这种方式可以配置的属性为: encoder , decoder, Contract , Logger , Retryer , ErrorDecoder , Request.Options , RequestInterceptor
其中重点是: @FeignClient(name = "stores", configuration = FooConfiguration.class) ,
也可以使用增加方式: FooConfiguration只配置需要的配置
@FeignClient(value = "stores", configuration = {FooConfiguration.class,DefaultEncoder.class, DefaultDecoder.class})
1
并且FooConfiguration配置类上, 无需标明@Configuration, 标明后就是全局配置了!
个人例子, 设置单个客户端读取超时
fegin接口
@FeignClient(value = "account-service-api", url = "${account-service.url}", path = "/accountActiveInfo",
configuration = AccountFeignRequest.class) // 使用自定义组合配置类
public interface AccountActiveInfoApi {
/**
* 查询不活跃用户
*
* @param accountQueryRqt
* @author: ZhiHao
* @date: 2022/5/25
*/
@PostMapping("/inactiveQuery")
AccountActiveInfoRsp<AccountRsp> inactiveQuery(@RequestBody InactiveQueryRqt accountQueryRqt);
}
AccountFeignRequest 配置类
注意无需配置@Configuration 注解, 配置后是会到 父Bean工厂上下文中
public class AccountFeignRequest {
@Bean
public Request.Options feignRequestOptions() {
return new Request.Options(10000,333*1000);
}
@Bean
public Encoder defaultEncoder() {
return new DefaultEncoder();
}
@Bean
public Decoder defaultDecoder() {
return new DefaultDecoder();
}
@Bean
public ErrorDecoder defaultErrorDecode() {
return new DefaultErrorDecode();
}
}
结果: