Spring-在网络代理后面启动
Spring-Boot behind a network proxy
我目前正在根据 this example. 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 this Whosebug 问题实施 OpenID 身份验证,但我不知道将代码放在哪里。如何为我的 spring 引导容器配置代理?
谢谢
不确定这是否有用,但我目前正在学习 Spring 引导教程 (https://spring.io/guides/gs/integration/) 并遇到类似的网络代理问题。仅通过提供 JVM 参数
即可解决此问题
-Dhttp.proxyHost=your.proxy.net -Dhttp.proxyPort=8080
仅添加提供的两个参数对我不起作用。
完整列表是这样的:
-Dhttp.proxyHost=somesite.com -Dhttp.proxyPort=4321
-Dhttps.proxyHost=somesite.com -Dhttps.proxyPort=4321 -Dhttps.proxySet=true
-Dhttp.proxySet=true
对我来说,application.properties
中的 server.use-forwarded-headers=true
解决了问题。
如果您需要它来调用外部服务,请尝试将代理设置为您正在使用的客户端(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);
我可以用两种方法解决问题
通过 JVM args(http 和 https)
-Dhttp.proxyHost=your-http-proxy-host -Dhttp.proxyPort=8080
-Dhttps.proxyHost=your-https-proxy-host -Dhttps.proxyPort=8080
或以编程方式
public static void setProxy() {
System.setProperty("http.proxyHost", "your-http-proxy-host");
System.setProperty("http.proxyPort", "8080");
System.setProperty("https.proxyHost", "your-http-proxy-host");
System.setProperty("https.proxyPort", "8080");
}
我目前正在根据 this example. 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 this Whosebug 问题实施 OpenID 身份验证,但我不知道将代码放在哪里。如何为我的 spring 引导容器配置代理?
谢谢
不确定这是否有用,但我目前正在学习 Spring 引导教程 (https://spring.io/guides/gs/integration/) 并遇到类似的网络代理问题。仅通过提供 JVM 参数
即可解决此问题-Dhttp.proxyHost=your.proxy.net -Dhttp.proxyPort=8080
仅添加提供的两个参数对我不起作用。 完整列表是这样的:
-Dhttp.proxyHost=somesite.com -Dhttp.proxyPort=4321
-Dhttps.proxyHost=somesite.com -Dhttps.proxyPort=4321 -Dhttps.proxySet=true
-Dhttp.proxySet=true
对我来说,application.properties
中的 server.use-forwarded-headers=true
解决了问题。
如果您需要它来调用外部服务,请尝试将代理设置为您正在使用的客户端(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);
我可以用两种方法解决问题
通过 JVM args(http 和 https)
-Dhttp.proxyHost=your-http-proxy-host -Dhttp.proxyPort=8080
-Dhttps.proxyHost=your-https-proxy-host -Dhttps.proxyPort=8080
或以编程方式
public static void setProxy() {
System.setProperty("http.proxyHost", "your-http-proxy-host");
System.setProperty("http.proxyPort", "8080");
System.setProperty("https.proxyHost", "your-http-proxy-host");
System.setProperty("https.proxyPort", "8080");
}