spring boot项目配置RestTemplate超时时长
配置类:
@Configuration
public class FeignConfiguration {
@Bean(name="remoteRestTemplate")
public RestTemplate RestTemplate(){
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(5000);
requestFactory.setReadTimeout(3500);
RestTemplate restTemplate = new RestTemplate(requestFactory);
return restTemplate;
}
}
调用:
@Service
@Slf4j
public class SlCustomerCreditSettingProductServiceImpl implements SlCustomerCreditSettingProductService {
@Autowired
private SlCustomerCreditSettingProductFeignClient slCustomerCreditSettingProductFeignClient;
@Autowired
@Qualifier(value = "remoteRestTemplate")
private RestTemplate restTemplate;
@Value("${crb_hub_url}")
private String crbHubUrl;
@Autowired
private MQServerService mqServerService; @Override
public List<SlCustomerCreditSettingProductRespVo> getCustomerCreditSettingProductRespVo(UserInfo userInfo) throws OpenHttpExection{
SlCustomerCreditSettingProductQueryVo slCustomerCreditSettingProductQueryVo = new SlCustomerCreditSettingProductQueryVo();
slCustomerCreditSettingProductQueryVo.setCorporationId(userInfo.getCorporationId());
slCustomerCreditSettingProductQueryVo.setCustomerId(userInfo.getCustomerId());
slCustomerCreditSettingProductQueryVo.setEffectiveEndDate(userInfo.getMakeDate());
slCustomerCreditSettingProductQueryVo.setMakeDate(userInfo.getMakeDate());
slCustomerCreditSettingProductQueryVo.setRegionCode(userInfo.getRegionCode());
List<SlCustomerCreditSettingProductRespVo> slCustomerCreditSettingProductRespVos = Lists.newArrayList(); ParameterizedTypeReference<List<CustomerCreditSettingProduct>> typeRef = new ParameterizedTypeReference<List<CustomerCreditSettingProduct>>() {};
ResponseEntity<List<CustomerCreditSettingProduct>> customerCreditSettingProductRespVos;
//post调用外部接口
try {
customerCreditSettingProductRespVos = restTemplate.exchange(
crbHubUrl+"/customerCreditSettingProductApiController/findByCustomerIdAndCorporationId",
HttpMethod.POST,
new HttpEntity<>(slCustomerCreditSettingProductQueryVo),
typeRef);
}catch (Exception e){
throw new OpenHttpExection(e.getMessage());
}
if(CollectionUtils.isNotEmpty(customerCreditSettingProductRespVos.getBody())) {
for (CustomerCreditSettingProduct o : customerCreditSettingProductRespVos.getBody()) {
SlCustomerCreditSettingProductRespVo slCustomerCreditSettingProductRespVo = new SlCustomerCreditSettingProductRespVo();
BeanUtils.copyProperties(o, slCustomerCreditSettingProductRespVo);
slCustomerCreditSettingProductRespVos.add(slCustomerCreditSettingProductRespVo);
}
//mq发送数据
SynSlCustomerCreditSettingProduct synSlCustomerCreditSettingProduct = new SynSlCustomerCreditSettingProduct();
synSlCustomerCreditSettingProduct.setCustomerCreditSettingProducts(customerCreditSettingProductRespVos.getBody());
synSlCustomerCreditSettingProduct.setSlCustomerCreditSettingProductQueryVo(slCustomerCreditSettingProductQueryVo);
try {
mqServerService.sendLoopCedit(synSlCustomerCreditSettingProduct);
}catch (Exception e){
e.printStackTrace();
log.error("同步客户信用体系设定数据到本地数据库失败!");
}
}
return slCustomerCreditSettingProductRespVos;
}
}
spring boot项目配置RestTemplate超时时长的更多相关文章
- Spring Boot 日志配置方法(超详细)
默认日志 Logback : 默认情况下,Spring Boot会用Logback来记录日志,并用INFO级别输出到控制台.在运行应用程序和其他例子时,你应该已经看到很多INFO级别的日志了. 从上图 ...
- Spring Boot项目配置RabbitMQ集群
//具体参看了配置的源码 org.springframework.boot.autoconfigure.amqp.RabbitProperties //RabbitMQ单机 spring: rab ...
- Spring Boot 项目配置的使用方法
第一种写法resources目录下的application.properties文件 第二种写法resources目录下的application.yml文件 在项目中获取配置项: 分组配置: (配置 ...
- spring boot项目配置跨域
1.在项目启动入口类实现 WebMvcConfigurer 接口: @SpringBootApplication public class Application implements WebMvcC ...
- spring boot 项目配置字符编码
- Docker 部署Spring Boot 项目并连接mysql、redis容器(记录过程)
Spring Boot 项目配置 将写好的Spring Boot 项目通过maven 进行package打包获得可执行Jar 再src/main/docker(放哪都行)下编写创建Dockerfile ...
- Spring Boot(IDEA,Gradle)超详细用户管理项目(一)——Hello World
1.构建工具的配置(Gradle):自定义-所有设置:构建.执行.部署-构建工具-Gradle: 设置Gradle用户主目录:(该目录相当于仓库,gradle将下载所需依赖到此目录下),此目录下可新建 ...
- Spring boot项目maven的profile多环境配置不自动替换变量的问题解决
Spring boot项目maven的profile多环境配置不自动替换变量的问题解决 在网上找了好久,配置都很简单,可是我的程序就是不能自动替换变量,最终单独测试,发现原来是引用spring b ...
- 让Spring Boot项目启动时可以根据自定义配置决定初始化哪些Bean
让Spring Boot项目启动时可以根据自定义配置决定初始化哪些Bean 问题描述 实现思路 思路一 [不符合要求] 思路二[满足要求] 思路三[未试验] 问题描述 目前我工作环境下,后端主要的框架 ...
随机推荐
- 过滤器(Filter)与拦截器(Interceptor)的区别
1 .拦截器是基于java的反射机制的,而过滤器是基于函数回调. 2 .拦截器不依赖与servlet容器,过滤器依赖与servlet容器. 3 .拦截器只能对action请求起作用,而过滤器则可以对几 ...
- JavaScript 数组复制的方法
1.循环 2.Array.from(arr) 3.let arr2 = [...arr]
- 关于animation的一些简单基础和使用方法记载
第一次写博客,只是单纯的想把我自己的一些心得和使用过的css3的animation的一些方法记录和总结,方便下次使用,我写的这些都是刚入门适合做一些简单的动画动作,过于复杂的还有待发掘或者使用别的方法 ...
- 关于对DI和IOC的概念理解
在spring框架学习过程中,涉及到两个新名词:DI和IOC.开始总是混淆两者的概念,稀里糊涂,后来上网搜了一下又和同学讨论之后,基本上理解了二者的概念.实际上DI(依赖注入)和IOC(控制反转)就是 ...
- JS--我发现,原来你是这样的JS(一)(初识,历史)
一.前言: 前段时间看红宝书(JavaScript高级程序设计),但没有计划的去看,也没有做详细的笔记,读了之后有点空虚,感觉不对劲啊,学的东西很难记住,印象不深啊,有种挫败感. 作前端的js都学不好 ...
- hadoop完全分布式的安装
下载地址: centos 7.5 下载地址 清华 http://mirrors.tuna.tsinghua.edu.cn/centos/7/isos/x86_64/CentOS-7-x86_64-DV ...
- Adapter中用不了getWindowManager()
在写popupwindow的时候一般会获取屏幕的宽高来设置popupwindow的宽高,但是在adapter中用不了getWindowManager(), 但是为什么Activity中就可以用getW ...
- Core Animation-1:图层树
图层的树状结构 >巨妖有图层,洋葱也有图层,你懂吗?我们都有图层 -- 史莱克 Core Animation其实是一个令人误解的命名.你可能认为它只是用来做动画的,但实际上它是从一个叫做*Lay ...
- fiddler常见的应用场景
在移动互联网时代,作为软件测试工程师,fiddler绝对是值得掌握并添加进技术栈里的工具之一. 那么,fiddler在日常的测试工作中,一般都有哪些常见的应用场景呢? 根据以往工作经验,大概有如下4类 ...
- c# 通过GroupBy 进行分组
有时候我们需要数据根据一些字段进行分组,这时候用orderBy很方便.不多说了.直接上代码: class Ma { public int number { get; set; } public str ...