C3P0 Failed to get local InetAddress for VMID solution in Linux environment

Reference: http://blog.csdn.net/top_code/article/details/38703769

Today, I used the C3P0 data source in a Java project. The program runs under Windows without any problems, but an exception occurs when it is deployed and run on the server (Linux environment). The exception information is as follows:

 

[html]  view plain copy  
 
  1. 2014-08-19 20:51:01 [INFO] Failed to get local InetAddress for VMID. This is unlikely to matter. At all. We'll add some extra randomness  
  2. java.net.UnknownHostException: w: w  
  3.     at java.net.InetAddress.getLocalHost(Unknown Source)  
  4.     at com.mchange.v2.c3p0.impl.C3P0ImplUtils.generateVmId(C3P0ImplUtils.java:120)  
  5.     at com.mchange.v2.c3p0.impl.C3P0ImplUtils.<clinit>(C3P0ImplUtils.java:98)  
  6.     at com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase.<init>(PoolBackedDataSourceBase.java:227)  
  7.     at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.<init>(AbstractPoolBackedDataSource.java:62)  
  8.     at com.mchange.v2.c3p0.ComboPooledDataSource.<init>(ComboPooledDataSource.java:109)  
  9.     at com.mchange.v2.c3p0.ComboPooledDataSource.<init>(ComboPooledDataSource.java:105)  
  10.     .......  
  11. Caused by: java.net.UnknownHostException: w  
  12.     at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)  
  13.     at java.net.InetAddress$1.lookupAllHostAddr(Unknown Source)  
  14.     at java.net.InetAddress.getAddressesFromNameService(Unknown Source)  
  15.     ... 23 more  


      

 

        At first glance, it seems inexplicable. I have never encountered such an exception. Finally, I found a solution on Google. First, I will explain the cause of this exception, and then give a solution.

problem causes

         Let's take a look at UnknownHostException: how w in w is obtained, cat /etc/sysconfig/network file, the content is as follows:

[html]  view plain copy  
 
  1. [root@w picture]# cat /etc/sysconfig/network  
  2. NETWORKING=yes  
  3. HOSTNAME=w  


          HOSTNAME=w, oh oh, when I saw this, I suddenly felt a sense of darkness. It turned out to be because the system did not find the IP corresponding to the host name w, just modify the Linux hosts file.

 


The reason for
          the error has been analyzed above, mainly because the system does not find the IP corresponding to the hostname w, and you can modify the Linux hosts file. The specific operation steps are as follows:
First, execute the cat /etc/hosts command, as follows:

 

[html]  view plain copy  
 
  1. [root@w picture]# cat /etc/hosts  
  2. 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4  
  3. ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6  

 

 

Then execute the vi /etc/hosts command

Add w after the first line 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 and save it.

The modified hosts file is as follows:

[html]  view plain copy  
 
  1. [root@w picture]# cat /etc/hosts  
  2. 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 w  
  3. ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6  

 

 

When Linux searches for a domain name, it usually means to search for the file /etc/hosts first, and then request the DNS server if it cannot be found.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326647800&siteId=291194637