In our development, if you want to obtain the IP address of the local machine, you can get it through Inetaddress.getlocalhost (), but a run-time exception that might be encountered is the corresponding configuration in the local configuration file. It's going to produce unknownhostexception. unknownhostexception cause the native name is not an IP address the native name is an IP address, but not the corresponding IP address of this computer The native name is an incomplete IP address with a different case solution
First we check the name of the machine by command line: [hostname]
Judging by the name of the machine is the reason for the above the solution to the host name is not an IP address
Host name If it is not the local IP address, you need to configure the host name and native IP through the format "IP native name" in the/etc/hosts file, so that the corresponding native name will get to the corresponding IP native name is an IP, but not the native IP
modifying the native IP host name to the correct native name is an incomplete IP
this situation in the acquisition process will not be reported unknownhostexception, but will access stagnation, the final report connection timed out of the exception, such cases need to modify the native name to the correct native IP corresponding string
- if the Inetaddress.getlocalhost () method is used in development, it is best to run a test in advance to see if you can get the correct IP for the deployed host