Java 网络代理背后的 Spring-Boot
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30168113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring-Boot behind a network proxy
提问by KenavR
I am currently implementing an OpenID authentication based on thisexample. Now I am developing behind a network proxy, therefore the server cannot connect to google. The java proxy settings seem to not have any effect. I also found thisstackoverflow question, but I cannot figure out where to put the code. How can I configure the proxy for my spring boot container?
我目前正在基于此示例实施 OpenID 身份验证。现在我在网络代理后面开发,因此服务器无法连接到谷歌。java代理设置似乎没有任何影响。我也发现了这个stackoverflow 问题,但我不知道把代码放在哪里。如何为我的 Spring Boot 容器配置代理?
thanks
谢谢
采纳答案by t_barbz
Not sure if this is of any use, but I'm just working through a Spring Boot tutorial currently (https://spring.io/guides/gs/integration/) and hit a similar network proxy issue. This was resolved just by providing the JVM arguments
不确定这是否有任何用处,但我目前只是在学习 Spring Boot 教程(https://spring.io/guides/gs/integration/)并遇到了类似的网络代理问题。这只是通过提供 JVM 参数解决的
-Dhttp.proxyHost=your.proxy.net -Dhttp.proxyPort=8080
回答by BadChanneler
Adding just the two provided arguments didn't work for me. Full list that did it is this:
仅添加两个提供的参数对我不起作用。这样做的完整列表是这样的:
-Dhttp.proxyHost=somesite.com -Dhttp.proxyPort=4321
-Dhttps.proxyHost=somesite.com -Dhttps.proxyPort=4321 -Dhttps.proxySet=true
-Dhttp.proxySet=true
回答by peterh - Reinstate Monica
For me, server.use-forwarded-headers=true
in application.properties
solved the problem.
对我来说,server.use-forwarded-headers=true
在application.properties
解决了这个问题。
回答by Aryan Nale
If you need this to make a call to an external service, then try to set proxy to the Client you are using (RestTemplate, etc), as below:
如果您需要它来调用外部服务,请尝试将代理设置为您正在使用的客户端(RestTemplate 等),如下所示:
HttpComponentsClientHttpRequestFactory requestFactory = new
HttpComponentsClientHttpRequestFactory();
DefaultHttpClient httpClient = (DefaultHttpClient) requestFactory.getHttpClient();
HttpHost proxy = new HttpHost("proxtserver", port);
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
restTemplate.setRequestFactory(requestFactory);