天天看点

[ActiveMQ]java.net.UnknownHostException: wl.example.com: wl.example.com

问题描述:

今天在配置ActiveMQ的时候,修改了ActiveMQ的配置文件:<broker brokerName="localhost" useJmx="false" xmlns= "http://activemq.org/config/1.0" >

启动的时候报错:

2018-12-13 11:46:54,123 INFO  [OsgiBundleXmlApplicationContext] Not publishing application context OSGi service for bundle CXF dOSGi Remote Service Admin Implementation (cxf-dosgi-ri-dsw-cxf)

2018-12-13 11:46:54,144 INFO  [OsgiBundleXmlApplicationContext] Publishing application context as OSGi service with properties {org.springframework.context.service.name=cxf-dosgi-ri-dsw-cxf, Bundle-SymbolicName=cxf-dosgi-ri-dsw-cxf, Bundle-Version=1.2.0}

2018-12-13 11:46:54,146 INFO  [DependencyWaiterApplicationContextExecutor] No outstanding OSGi service dependencies, completing initialization for OsgiBundleXmlApplicationContext(bundle=com.ygsoft.ecp.service.mail.impl, config=osgibundle:/META-INF/spring/*.xml)

2018-12-13 11:46:54,154 WARN  [IdGenerator] could not generate unique stub

java.net.UnknownHostException: wl.example.com: wl.example.com

    at java.net.InetAddress.getLocalHost(InetAddress.java:1402)

    at org.apache.activemq.util.IdGenerator.<clinit>(IdGenerator.java:52)

    at org.apache.activemq.ActiveMQConnection.<clinit>(ActiveMQConnection.java:110)

    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:288)

    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:256)

    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:227)

    at org.apache.activemq.ActiveMQConnectionFactory.createTopicConnection(ActiveMQConnectionFactory.java:205)

    at net.sf.ehcache.distribution.jms.JMSCacheManagerPeerProviderFactory.createTopicConnection(JMSCacheManagerPeerProviderFactory.java:147)

    at net.sf.ehcache.distribution.jms.JMSCacheManagerPeerProviderFactory.createCachePeerProvider(JMSCacheManagerPeerProviderFactory.java:121)

    at net.sf.ehcache.config.ConfigurationHelper.createCachePeerProviders(ConfigurationHelper.java:132)

    at net.sf.ehcache.CacheManager.configure(CacheManager.java:648)

    at net.sf.ehcache.CacheManager.doInit(CacheManager.java:408)

    at net.sf.ehcache.CacheManager.init(CacheManager.java:358)

    at net.sf.ehcache.CacheManager.<init>(CacheManager.java:243)

    at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:985)

    at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:961)

    at com.ygsoft.ecp.service.cache.impl.ehcache.EhcacheFactory.createCacheManager(EhcacheFactory.java:44)

    at com.ygsoft.ecp.service.cache.impl.ehcache.EhcacheAdapter.startCacheService(EhcacheAdapter.java:363)

    at com.ygsoft.ecp.service.cache.impl.manager.CacheServiceManager.startCacheService(CacheServiceManager.java:380)

    at com.ygsoft.ecp.service.cache.impl.manager.CacheServiceBean.init(CacheServiceBean.java:65)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1581)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1522)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)

    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)

    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)

    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:589)

    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)

    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$14(AbstractDelegatedExecutionApplicationContext.java:1)

    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:363)

    at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)

    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:322)

    at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:143)

    at java.lang.Thread.run(Thread.java:662)

2018-12-13 11:46:54,210 INFO  [WFBean] 注册获取流程服务器配置消息监听器成功!

2018-12-13 11:46:54,211 INFO  [OsgiBundleXmlApplicationContext] Publishing application context as OSGi service with properties {org.springframework.context.service.name=com.ygsoft.ecp.service.cache.web, Bundle-SymbolicName=com.ygsoft.ecp.service.cache.web, Bundle-Version=4.2.0}

2018-12-13 11:46:54,213 INFO  [ContextLoaderListener] Application context successfully refreshed (OsgiBundleXmlApplicationContext(bundle=cxf-dosgi-ri-dsw-cxf, config=osgibundle:/META-INF/spring/*.xml))

2018-12-13 11:46:54,234 INFO  [OsgiBundleXmlApplicationContext] Bean 'org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

2018-12-13 11:46:54,235 INFO  [OsgiBundleXmlApplicationContext] Bean 'org.springframework.transaction.config.internalTransactionAdvisor' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

2018-12-13 11:46:54,242 INFO  [GapOsgiBundleApplicationContextListener] 服务包[com.ygsoft.ecp.service.cache.web]开始进行资源注册

2018-12-13 11:46:54,243 INFO  [HttpServiceTracker] 服务包[com.ygsoft.ecp.service.cache.web]正在进行资源注册

2018-12-13 11:46:54,243 INFO  [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@55ab9655: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,mailServiceFactory,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,transactionManager,org.springframework.osgi.extensions.annotation.ServiceReferenceInjectionBeanPostProcessor#0,com.ygsoft.ecp.core.framework.annotations.OSGiServiceBeanPostProcessor#0]; root of factory hierarchy

2018-12-13 11:46:54,243 INFO  [HttpServiceTracker] 注册Servlet[CacheManageServlet,/ecp/cache2/CacheManageServlet]成功

2018-12-13 11:46:54,244 INFO  [HttpServiceTracker] 注册Servlet[CacheStatisticServlet,/ecp/cache2/CacheStatisticServlet]成功

2018-12-13 11:46:54,244 INFO  [HttpServiceTracker] 注册Resource资源[/ecp/cache2]成功

问题分析:

根据日志java.net.UnknownHostException: localhost判断,应该是由于服务器无法正确解析localhost造成的

[[email protected] conf]$ ping localhost

ping: unknown host localhost

[[email protected] conf]$ ping 127.0.0.1

PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.

64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.020 ms

64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.026 ms

64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.023 ms

根据日志Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService' defined in class path resource [activemq.xml]判断,应该是activemq.xml文件中的BrokerService配置出错

解决方式:

一:不使用localhost而使用127.0.0.1代替

二:修改主机映射

[[email protected] test]# vi /etc/hosts

在打开的文件中增加下面一行(保证新增的这条为以127.0.0.1开头的第一个):

127.0.0.1               localhost.localdomain localhost

出现如下测试结果说明配置成功:

[[email protected] test]# ping localhost

PING localhost.localdomain (127.0.0.1) 56(84) bytes of data.

64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=1 ttl=64 time=0.019 ms

64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=2 ttl=64 time=0.020 ms

64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=3 ttl=64 time=0.024 ms

64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=4 ttl=64 time=0.020 ms

64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=5 ttl=64 time=0.018 ms

--- localhost.localdomain ping statistics ---

5 packets transmitted, 5 received, 0% packet loss, time 4009ms

rtt min/avg/max/mdev = 0.018/0.020/0.024/0.003 ms

此时可以在配置文件中使用localhost,服务器会将localhost解析为127.0.0.1