Specifying an http proxy with spring-boot

前端 未结 4 2179
没有蜡笔的小新
没有蜡笔的小新 2021-01-03 00:08

How do I specify a http proxy to use when running a spring-boot fat war as a tomcat server?

I have tried the following which is not working.

java -ja         


        
4条回答
  •  -上瘾入骨i
    2021-01-03 00:39

    Put the JVM options before -jar. This should work:

    java -Dhttp.proxyHost=localhost -Dhttp.proxyPort=3128 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128 -jar my-application.war

    Explanation

    According to java command-line documentation, the command's syntax is:

    java [ options ] -jar file.jar [ arguments ]

    The arguments are the args that'll be received in your main(String[] args). So, it's totally your responsibility to use them somehow. And if you forward them to spring using SpringApplication.run(MyApplication.class, args);, then you need to find documentation that says how spring uses args in the run method.

    The options, however, are not sent to your app. One of their uses is to set what java calls system properties using -Dproperty=value. According to Java Networking and Proxies, setting, e.g., http.proxyHost property makes the JVM proxy all your http request through that host.

提交回复
热议问题