2016-01-20 27 views
0

有沒有什麼辦法在春季開機配置中設置網絡代理和憑證?春季開機設置代理相關信息

請幫我一把。

我正在使用RestTemplate調用其餘api。

+1

你看過http://stackoverflow.com/questions/3687670/using-resttemplate-how-to-send-the-request-to-a -proxy-first-so-i-can-use-my-jun? – reto

回答

1

你應該使用下面的代碼啓用代理網頁摘要

SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); 
    InetSocketAddress address = new InetSocketAddress(host,portNr); 
    Proxy proxy = new Proxy(Proxy.Type.HTTP,address); 
    factory.setProxy(proxy); 

    restTemplate.setRequestFactory(factory); 
+0

有沒有可能在application.properties文件中配置。 –

+0

@Goutham可以使用PropertySource註釋和值註釋。請參閱示例http://www.mkyong.com/spring/spring-propertysources-example/ –