問題描述:
今天在配置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