基于扫描方式配置:
引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
启动类添加注解:@EnableFeignClients
Config:
@Configuration
public class FeigTimeOutConfigure {
@Value("${fegin.connect.time.out.millis}")
private Integer connectTimeOutMillis; //链接超时时间
@Value("${fegin.read.time.out.millis}")
private Integer readTimeOutMillis; //响应超时时间,如果超过readTimeOutMillis秒没有接过发起下一次请求
@Value("${fegin.period}")
private Integer period; //发起当前请求的时间间隔,单位毫秒
@Value("${fegin.max.period}")
private Integer maxPeriod; //发起当前请求的最大时间间隔,单位毫秒
@Value("${fegin.max.attempts}")
private Integer maxAttempts; //最多请求次数,包括第一次
@Bean
public Request.Options options() {
return new Request.Options(connectTimeOutMillis, readTimeOutMillis);
}
@Bean
public Retryer feignRetryer() {
Retryer retryer = new Retryer.Default(period, maxPeriod, maxAttempts);
return retryer;
}
}
码云:(https://gitee.com/wu_xiaoxi/spring-family/tree/master/springboot-openfegin)