public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void configureAsyncSupport(final AsyncSupportConfigurer configurer) {
configurer.setDefaultTimeout(20000);
configurer.registerCallableInterceptors(timeoutInterceptor());
@Bean
public TimeoutCallableProcessingInterceptor timeoutInterceptor() {
return new TimeoutCallableProcessingInterceptor();
3、RestTemplate超时
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
@Slf4j
@Configuration
public class RestTemplateConfig {
@Bean
@ConfigurationProperties(prefix = "rest.connection")
public HttpComponentsClientHttpRequestFactory httpRequestFactory() {
return new HttpComponentsClientHttpRequestFactory();
@Bean
public RestTemplate customRestTemplate(){
return new RestTemplate(httpRequestFactory());
@Beanpublic SimpleClientHttpRequestFactory httpRequestFactory() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(1000);
requestFactory.setReadTimeout(1000);
return requestFactory;
@Beanpublic RestTemplate customRestTemplate(){
return new RestTemplate(httpRequestFactory());