2017-09-23 48 views
0

我用春RestTemplate getForObject包含重複標題重複使用它多次請求後

@Autowired 
private RestTemplate restTemplate; 

在我的每一個用法。我初始化RestTemplate在我的應用程序類爲:

@Bean 
public RestTemplate restTemplate() { 

    SimpleClientHttpRequestFactory httpRequestFactory = new SimpleClientHttpRequestFactory(); 
    httpRequestFactory.setConnectTimeout(30 * 1000); 
    httpRequestFactory.setReadTimeout(30 * 1000); 

    return new RestTemplate(httpRequestFactory); 
} 

請建議我爲這個問題的原因。還糾正我,如果我在錯誤的反正。

+0

表現出一定的日誌。 – Barath

+1

就我所知'@ Bean'創建一個單例 –

回答

-1

試圖改變與@Component的@Bean,讓我知道,如果它

0

最後,我找到了一個解決方案,以避免重複的標題:

@Bean 
public RestTemplate restTemplate() { 
    RestTemplate restTemplate = new RestTemplate(); 
    restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8"))); 
    return restTemplate; 
}