In Java 8, how do I get my hostname without hard-coding it in my environment?
问题 We just upgraded to Java 8 on Amazon Linux. We are using Spring 4.3.8.RELEASE. It used to be that we could get our machine hostname by setting up beans in our application context file like so ... <bean id="localhostInetAddress" class="java.net.InetAddress" factory-method="getLocalHost" /> <bean id="hostname" factory-bean="localhostInetAddress" factory-method="getHostName" /> But with Java 8, the bean "hostname" now contains the string localhost Before Java 8, it used to contain the "hostname"