springboot如何设置接口的响应时间

springboot如何设置接口的响应时间

两张方法

1、在配置文件application.properties中或者application.yml加上spring.mvc.async.request-timeout=30000,意思是设置超时时间为30000ms即30s

spring.mvc.async.request-timeout=30000
spring:
  mvc:
    async:
      request-timeout: 30000

2、在config配置类里配置


public class WebMvcConfig extends WebMvcConfigurerAdapter {
    
    
 @Override
  public void configureAsyncSupport(final AsyncSupportConfigurer configurer) {
    
    
    configurer.setDefaultTimeout(30000);
    configurer.registerCallableInterceptors(timeoutInterceptor());
  }
 @Bean
 public TimeoutCallableProcessingInterceptor timeoutInterceptor() {
    
    
   return new TimeoutCallableProcessingInterceptor();
 }
}

猜你喜欢

转载自blog.csdn.net/nyasm/article/details/118344180