问题
I am attempting to connect a spring rest service to a client which is an android device.
I have followed this tutorial on creating my service: https://spring.io/guides/gs/rest-service/ Which by default runs the Spring Service on port 8080.
My issue is that on localhost:8080/test I get a correct output from my service but on 127.0.0.1:8080/test I get 404 Not found.
Is there any reason for this? I specifically need to connect to 127.0.0.1 for debugging purposes with an android emulator.
Thank you.
回答1:
This could be because Java 7+ is using IPv6 as the default instead of IPv4. Thus localhost resolves into :::1 instead of 127.0.0.1.
Try the following:
Just pass -Djava.net.preferIPv4Stack=true to java VM options.
If this works you can make it permanent by setting _JAVA_OPTIONS on Linux:
export _JAVA_OPTIONS="-Djava.net.preferIPv4Stack=true"
You can place the above line inside /etc/profile or /etc/profile.d/java.sh (by creating the file java.sh)
来源:https://stackoverflow.com/questions/35470838/localhost-vs-127-0-0-1-in-spring-framework