Spring-Boot behind a network proxy

2020-02-10 05:42发布

I am currently implementing an OpenID authentication based on 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 stackoverflow question, but I cannot figure out where to put the code. How can I configure the proxy for my spring boot container?

thanks

5条回答
女痞
2楼-- · 2020-02-10 06:10

If you are using Intellij go to this file C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.2\plugins\maven\lib\maven3\conf

Change security settings so you can edit.

<proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username></username>
      <password></password>
      <host>Enter Your Host Here</host>
      <port>8080</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    <proxy>
      <id>optional2</id>
      <active>true</active>
      <protocol>https</protocol>
      <username></username>
      <password></password>
      <host>Enter Your Host Here</host>
      <port>8080</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
查看更多
再贱就再见
3楼-- · 2020-02-10 06:11

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

-Dhttp.proxyHost=your.proxy.net -Dhttp.proxyPort=8080
查看更多
男人必须洒脱
4楼-- · 2020-02-10 06:13

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
查看更多
Explosion°爆炸
5楼-- · 2020-02-10 06:22

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:

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);
查看更多
虎瘦雄心在
6楼-- · 2020-02-10 06:31

For me, server.use-forwarded-headers=true in application.properties solved the problem.

查看更多
登录 后发表回答