springboot设置接口超时
springboot 设置接口超时
1、配置文件 application.properties中加了,意思是设置超时时间为20000ms即20s,
spring.mvc.async.request-timeout=20000
2、config配置类
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超时
设置配置HttpComponentsClientHttpRequestFactory中的RequestConfig属性
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;
}
@Bean
public RestTemplate customRestTemplate(){
return new RestTemplate(httpRequestFactory());
}
application.properties:
#restTemplate配置
# 连接不共用的时候,等待连接超时。
rest.connection.connectionRequestTimeout=30000
# 建立连接超时
rest.connection.connectTimeout=30000
# 建立连接成功后 从服务器读取超时
rest.connection.readTimeout=30000
或者
#restTemplate配置
rest.connection.connection-request-timeout=30000
rest.connection.connect-timeout=30000
rest.connection.read-timeout=30000
来源于:
https://blog.csdn.net/qq_35860138/article/details/88941558
https://blog.csdn.net/weixin_34114823/article/details/86015073
springboot设置接口超时的更多相关文章
- 【轮询】【ajax】【js】【spring boot】ajax超时请求:前端轮询处理超时请求解决方案 + spring boot服务设置接口超时时间的设置
场景描述: ajax设置timeout在本机测试有效,但是在生产环境等外网环境无效的问题 1.ajax的timeout属性设置 前端请求超时事件[网络连接不稳定时候,就无效了] var data = ...
- springboot设置session超时和session监听
2.0版本以下设置session超时时间 1. springboot 2.0版本以下配置session超时 1.1 application.properties配置文件: spring.sessio ...
- Springboot 设置session超时
使用版本 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring ...
- Springboot设置session超时时间
按优先级高到低说: 第一种: spring boot 启动类里面: package com.mycenter; import org.mybatis.spring.annotation.MapperS ...
- postman接口超时设置,用于debug等断点调试
Settings->General->Request Timeout in ms(0 for infinity):设置请求超时的时间,默认为0
- Retrofit2.0 设置 连接超时
Retrofit2.0 这个网络请求框架使用了很久了,最近一次出现一个小插曲. 有一个接口,返回的数据量因为业务的原因 会返回很大的数据量,此时网络不大好的情况下,会出现请求失败的情况 也就是回调了 ...
- 转 HttpClient 设置连接超时时间
要: HttpClient 4.5版本升级后,设置超时时间的API又有新的变化,请大家关注. HttpClient升级到4.5版本后,API有很多变化,HttpClient 4之后,API一直没有太稳 ...
- HttpClient设置连接超时时间
https://www.cnblogs.com/winner-0715/p/7087591.html 使用HttpClient,一般都需要设置连接超时时间和获取数据超时时间.这两个参数很重要,目的是为 ...
- 【多线程】java多线程Completablefuture 详解【在spring cloud微服务之间调用,防止接口超时的应用】【未完成】
参考地址:https://www.jianshu.com/p/6f3ee90ab7d3 示例: public static void main(String[] args) throws Interr ...
随机推荐
- vue之安装配置
直接上图
- mysql导出 数据库字典
USE information_schema; --切记这里不能忘掉 SELECT T.TABLE_SCHEMA AS '数据库名称', T.TABLE_NAME AS '表名', T.TABLE_T ...
- linux--安装phpcurl扩展
在UBUNTU中直接用APT包管理工具安装: apt-get install curl libcurl3 libcurl3-dev php5-curl 安装好后重启Apache服务器就行了,如果还是不 ...
- 初学者遇到的PostgreSQL字符集问题的解决
当初学者在使用PostgreSQL数据库,输入中文时,会遇到“ERROR: invalid byte sequence for encoding "UTF8": 0xd6d0”的 ...
- 创建纯文本Banner
场景: 最近再学习Spring Boot的过程中,想要自定义一个Banner,就是再工程启动是输出的那个文本图案,但是自己拼写既麻烦又不好看,所以找到一个工具,自动输出文字代表的纯文本Banner,例 ...
- linux的僵尸进程和孤儿进程
1 僵尸进程: 子进程已经退出勒 但是还没有回收资源的进程为僵尸进程 代码验证 #include <stdio.h> #include <stdlib.h> #include ...
- css里关于浏览器的前缀
今天遇到一个比较坑爹的 -moz-box-sizing: border-box; box-sizing' border-box; 一下子有点懵逼,第一个什么鬼??一查,原来是火狐浏览器的前缀.应该 ...
- hdoj4180
题意: 使(a/b-c/d)最小,然后让你求c/d. 我们能说最小the error |A/B - C/D| 然后C,D的范围是 0 < C < D < B. 其实就是:求接近(A/ ...
- python string类型 bytes类型 bytearray类型
一.python3对文本和二进制数据做了区分.文本是Unicode编码,str类型,用于显示.二进制类型是bytes类型,用于存储和传输.bytes是byte的序列,而str是unicode的序列. ...
- 黑客攻防技术宝典web实战篇:解析应用程序习题
猫宁!!! 参考链接:http://www.ituring.com.cn/book/885 随书答案. 1. 当解析一个应用程序时,会遇到以下 URL:https://wahh-app.com/Coo ...