springboot服务调用超时_springboot设置接口超时

本文介绍了如何在SpringBoot中设置接口超时,包括在`application.properties`中设置默认超时时间,通过`WebMvcConfig`配置异步支持,以及使用`RestTemplate`定制请求超时。详细步骤包括配置文件中的设置、自定义拦截器以及`HttpComponentsClientHttpRequestFactory`和`SimpleClientHttpRequestFactory`的使用。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值