springboot 设置接口超时
1、配置文件 application.properties中加了,意思是设置超时时间为20000ms即20s,
spring.mvc.async.request-timeout=20000
2、config配置类
public class WebMvcConfig extendsWebMvcConfigurerAdapter {
@Overridepublic void configureAsyncSupport(finalAsyncSupportConfigurer configurer) {
configurer.setDefaultTimeout(20000);
configurer.registerCallableInterceptors(timeoutInterceptor());
}
@BeanpublicTimeoutCallableProcessingInterceptor timeoutInterceptor() {return newTimeoutCallableProcessingInterceptor();
}
}
3、RestTemplate超时
设置配置HttpComponentsClientHttpRequestFactory中的RequestConfig属性
importlombok.extern.slf4j.Slf4j;importorg.springframework.boot.context.properties.ConfigurationProperties;importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Configuration;imp