This commit is contained in:
wangkang
2017-07-29 10:18:35 +08:00
parent e1c9f3f372
commit e39c997fb5
3 changed files with 53 additions and 4 deletions
@@ -52,6 +52,30 @@ public class ApplicationConfig {
*/
private ThreadPoolProperties threadPool;
/**
* 描述 : 如有大文件通过restTemplate传输,请设置为false
*/
@NotNull
private Boolean bufferRequestBody = true;
/**
* 描述 : 获取bufferRequestBody
*
* @return the bufferRequestBody
*/
public Boolean getBufferRequestBody() {
return bufferRequestBody;
}
/**
* 描述 : 设置bufferRequestBody
*
* @param bufferRequestBody the bufferRequestBody to set
*/
public void setBufferRequestBody(Boolean bufferRequestBody) {
this.bufferRequestBody = bufferRequestBody;
}
/**
* 描述 : 获取threadPool
*
@@ -6,11 +6,14 @@
*/
package com.egridcloud.udf.core;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Primary;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableAsync;
@@ -35,6 +38,12 @@ import com.fasterxml.jackson.databind.module.SimpleModule;
@EnableScheduling
public class BaseApplication {
/**
* 描述 : applicationConfig
*/
@Autowired
private ApplicationConfig applicationConfig;
/**
* 描述 : xssObjectMapper
*
@@ -57,11 +66,24 @@ public class BaseApplication {
/**
* 描述 : externalRestTemplate
*
* @param requestFactory requestFactory
* @return RestTemplate
*/
@Bean(name = "externalRestTemplate")
public RestTemplate externalRestTemplate() {
return new RestTemplate();
public RestTemplate externalRestTemplate(ClientHttpRequestFactory requestFactory) {
return new RestTemplate(requestFactory);
}
/**
* 描述 : requestFactory
*
* @return ClientHttpRequestFactory
*/
@Bean
public ClientHttpRequestFactory requestFactory() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setBufferRequestBody(applicationConfig.getBufferRequestBody());
return requestFactory;
}
/**
@@ -12,6 +12,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
@@ -38,12 +39,14 @@ public class RmsConfig {
/**
* 描述 : restTemplate
*
* @param requestFactory requestFactory
*
* @return restTemplate
*/
@Bean
@LoadBalanced
RestTemplate restTemplate() {
return new RestTemplate();
RestTemplate restTemplate(ClientHttpRequestFactory requestFactory) {
return new RestTemplate(requestFactory);
}
/**