最近升级springboot 3,突然发现配置文件中的openFeign的超时时间设置不生效了
之前配置如下:
feign:
client:
config:
default:
connectTimeout: 3000
readTimeout: 5000
查资料都是说ribbon或者hystrix的超时时间设置问题,但实际并不是,没办法,去看源码,在FeignClientFactoryBean这个类里的
protected void configureFeign(FeignClientFactory context, Feign.Builder builder) {FeignClientProperties properties = this.beanFactory != null ? (FeignClientProperties)this.beanFactory.getBean(FeignClientProperties.class) : (FeignClientProperties)this.applicationContext.getBean(FeignClientProperties.class);FeignClientConfigurer feignClientConfigurer = (FeignClientConfigurer)this.getOptional(context, FeignClientConfigurer.class);this.setInheritParentContext(feignClientConfigurer.inheritParentConfiguration());if (properties != null && this.inheritParentContext) {if (properties.isDefaultToProperties()) {this.configureUsingConfiguration(context, builder);this.configureUsingProperties((FeignClientProperties.FeignClientConfiguration)properties.getConfig().get(properties.getDefaultConfig()), builder);this.configureUsingProperties((FeignClientProperties.FeignClientConfiguration)properties.getConfig().get(this.contextId), builder);} else {this.configureUsingProperties((FeignClientProperties.FeignClientConfiguration)properties.getConfig().get(properties.getDefaultConfig()), builder);this.configureUsingProperties((FeignClientProperties.FeignClientConfiguration)properties.getConfig().get(this.contextId), builder);this.configureUsingConfiguration(context, builder);}} else {this.configureUsingConfiguration(context, builder);}}
可以看到配置是从FeignClientProperties这里读的
完后进入这个类,发现注解
@ConfigurationProperties("spring.cloud.openfeign.client")
对比之前的版本,这个类的注解为
@ConfigurationProperties("feign.client")
所以问题很明显了,将配置改为
spring:
cloud:
openfeign:
client:
config:
default:
connectTimeout: 3000
readTimeout: 5000
问题解决
多说两句,其实除了看源码,直接看官网可能更直接一点
https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html/#timeout-handling