spring-projects / spring-boot

Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss.
https://spring.io/projects/spring-boot
Apache License 2.0
75.23k stars 40.7k forks source link

spring.bat can't work through proxy when pass -Dhttp.nonProxyHosts #9779

Closed liaoya closed 7 years ago

liaoya commented 7 years ago

I use springboot cli on windows, but my PC is behind a proxy, so that I set JAVA_OPTS before call spring.bat. I need escape "|" for batch file on Windows, you can refer http://www.robvanderwoude.com/escapechars.php or https://stackoverflow.com/questions/25744252/bypassing-non-proxy-hosts-in-java-opts

set JAVA_OPTS="-Dhttp.proxyHost=proxy.company -Dhttp.proxyPort=80 -Dhttp.nonProxyHosts=127.0.0.1^|localhost^|10.*  -Dhttps.proxyHost=proxy.company -Dhttps.proxyPort=80 -Dhttps.nonProxyHosts=127.0.0.1^|localhost^|10.*"

springboot cli fails and the error message is

Using service at https://start.spring.io
Failed to retrieve metadata from service at 'https://start.spring.io' (Connect to start.spring.io:443 [start.spring.io/104.17.47.2, start.spring.io/104.17.46.2] failed: Connection timed out: connect)

I find the fix by change the line of spring.bat, use quote to surrender %JAVA_OPTS%. Now it works

"%JAVA_EXE%" %JAVA_OPTS% -cp "%CLASSPATH%" org.springframework.boot.loader.JarLauncher %CMD_LINE_ARGS%

to

"%JAVA_EXE%" "%JAVA_OPTS%" -cp "%CLASSPATH%" org.springframework.boot.loader.JarLauncher %CMD_LINE_ARGS%

The linux cli has no such issue.

snicoll commented 7 years ago

I don't think we should make that change. Rather, can you please quote the instruction properly, e.g.

set "JAVA_OPTS=-Dhttp.proxyHost=proxy.company -Dhttp.proxyPort=80 -Dhttp.nonProxyHosts=127.0.0.1^|localhost^|10.*  -Dhttps.proxyHost=proxy.company -Dhttps.proxyPort=80 -Dhttps.nonProxyHosts=127.0.0.1^|localhost^|10.*"

(so to be clear, the first quote should be set around the complete instruction rather than only the value). Can you please try and report if that fixes your issue?

liaoya commented 7 years ago

@snicoll It works. Thank you very much. I know the real problem comes from http.nonProxyHosts and https.nonProxyHosts. If I remove these two settings, it works very well.

Would springboot team can add this in its document. The proxy setting is always a challenge. Maven configuration has its own setting and the same as Gradle.

snicoll commented 7 years ago

Closing in favour of PR #10727