java. net. Unknownhostexception: Test: Test: unknown error failed to get the local InetAddress of VMID

I'm in spring-jersey 1 C 3p0 is used for connection pooling in restful web services When I started the application, I received the following error:

[com.mchange.v2.c3p0.impl.C3P0ImplUtils] INFO - Failed to get local InetAddress for VMID. This is unlikely to matter. At all. We'll add some extra randomness
java.net.UnkNownHostException: Test: Test: unkNown error
    at java.net.InetAddress.getLocalHost(InetAddress.java:1484)
    at com.mchange.v2.c3p0.impl.C3P0ImplUtils.generateVmId(C3P0ImplUtils.java:120)
    at com.mchange.v2.c3p0.impl.C3P0ImplUtils.<clinit>(C3P0ImplUtils.java:98)
    at com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase.<init>(PoolBackedDataSourceBase.java:227)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.<init>(AbstractPoolBackedDataSource.java:62)
    at com.mchange.v2.c3p0.ComboPooledDataSource.<init>(ComboPooledDataSource.java:109)
    at com.mchange.v2.c3p0.ComboPooledDataSource.<init>(ComboPooledDataSource.java:105)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.instantiateBean(AbstractAutowireCapablebeanfactory.java:1069)
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.createBeanInstance(AbstractAutowireCapablebeanfactory.java:1021)
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.doCreateBean(AbstractAutowireCapablebeanfactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.createBean(AbstractAutowireCapablebeanfactory.java:475)
    at org.springframework.beans.factory.support.Abstractbeanfactory$1.getObject(Abstractbeanfactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.Abstractbeanfactory.doGetBean(Abstractbeanfactory.java:300)
    at org.springframework.beans.factory.support.Abstractbeanfactory.getBean(Abstractbeanfactory.java:195)
    at org.springframework.beans.factory.support.DefaultListablebeanfactory.preInstantiateSingletons(DefaultListablebeanfactory.java:703)
    at org.springframework.context.support.AbstractApplicationContext.finishbeanfactoryInitialization(AbstractApplicationContext.java:760)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$startChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$startChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.UnkNownHostException: Test: unkNown error
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:907)
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1302)
    at java.net.InetAddress.getLocalHost(InetAddress.java:1479)
    ... 35 more

Who knows what this mistake is?

My spring datasource The XML files are:

<!-- <context:property-placeholder location="/WEB-INF/spring.properties"></context:property-placeholder> -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close"
    p:driverClass="com.MysqL.jdbc.Driver"
    p:jdbcUrl="jdbc:MysqL://localhost:3306/test2" 
    p:user="root" 
    p:password="root"
    p:acquireIncrement="5" 
    p:idleConnectionTestPeriod="60" 
    p:maxPoolSize="100"
    p:maxStatements="50" 
    p:minPoolSize="10" />

And POM xml:

<dependency>
    <groupId>c3p0</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.1.2</version>
</dependency>

Solution

Therefore, in order to prevent over engineering of serializing many c3p0 data sources into distributed storage in unlikely events, c3p0 attempts to provide globally unique "identitytoken" for each data source, which is partially realized by prefixing "VMID", with the intention (perhaps not surprising) to become the unique identifier of the current JVM

The VMID part is determined by the Internet address of the host running it So c3p0 calls Java net. InetAddress. Getlocalhost() to find However, due to security reasons or some configuration errors, Java net. InetAddress. The call to getlocalhost() may fail abnormally

All this is terrible, terrible over correction After writing, I am very shy, but I theoretically think that identitytoken may conflict, violating the possibility that an identitytoken should be mapped to an invariant of a unique pool So, that's it

So we can't find the local address oh dear. Let's go back and add a bunch of randomness to the VMID we will generate for the VM you are running, so as to reduce the unlimited possibility of conflict in practice Then we moved on As the error message said, "it's not very important. It's no problem at all."

If you want the error to disappear, you need to solve the problem that caused the call to getlocalhost() to fail in your environment But you can really ignore that

(it seems that your environment is IPv6, which may be related to it. I should study whether this code is suitable for including IPv6 address in VMID. But your code is far from enough.)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>