扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
原来在项目加入ActiveMQ之前,已经使用Dubbo,Redis,并且admin端和user端已经能够相互调用,但是加入ActiveMQ与ActiveMQ的连接池,并且通过xml文件配置好spring与ActiveMQ整合后,启动项目直接报错!不管是作为服务提供方的admin还是服务调用方的user都报如下错误!以致于项目启动失败!
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'houseService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could no
t autowire field: private org.springframework.jms.core.JmsTemplate com.codingpang.admin.service.impl.HouseServiceImpl.jmsTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'jmsTemplate' defined in class path resource [spring/applicationContext-jms.xml]: Cannot resolve reference to bean 'singleConnectionFactory' while setting bean property 'connectionFactory'; nested exception is org.springframew
ork.beans.factory.BeanCreationException: Error creating bean with name 'singleConnectionFactory' defined in class path resource [spring/applicationContext-jms.xml]: Cannot resolve reference to bean 'connectionFactory' while setting
bean property 'targetConnectionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'connectionFactory' defined in class path resource [spring/applicationContext-jms.xm
l]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at
。。。。 此处省略三千字。。。。
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jms.core.JmsTemplate com.codingpang.admin.service.impl.HouseServiceImpl.jmsTemplate; nested exception is org.s
pringframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsTemplate' defined in class path resource [spring/applicationContext-jms.xml]: Cannot resolve reference to bean 'singleConnectionFactory' while set
ting bean property 'connectionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'singleConnectionFactory' defined in class path resource [spring/applicationContext-j
ms.xml]: Cannot resolve reference to bean 'connectionFactory' while setting bean property 'targetConnectionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'connectionFactory' defined in class path resource [spring/applicationContext-jms.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
at
。。。。 此处省略三千字。。。。
... 67 more
异常分析:考虑到我是一名强迫症,我从上往下去阅读了一下异常,上面的异常是我先从上百行异常信息中从上往下提取出的关键信息,我们来分析下:
首先找到第一个Caused by:
,异常分析开始:
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jms.core.JmsTemplate com.codingpang.admin.service.impl.HouseServiceImpl.jmsTemplate;
1.第一句异常:不能在com.codingpang.admin.service.impl.HouseServiceImpl
这个类中将org.springframework.jms.core.JmsTemplate
这个对象注入到com.codingpang.admin.service.impl.HouseServiceImpl.jmsTemplate
属性;
下图可以看出我在HouseServiceImpl
中的确在注入JmsTemplate
对象
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsTemplate' defined in class path resource [spring/applicationContext-jms.xml]: Cannot resolve reference to bean 'singleConnectionFactory' while setting bean property 'connectionFactory';
2 第二句异常:在类路径下的spring类路径下的applicationContext-jms.xml文件中创建名为jmsTemplate的bean错误,(原因是:)在设置bean属性值的时候,不能将 'connectionFactory’引用到名为’singleConnectionFactory’的bean,我们顺着这句异常,看看我的配置文件applicationContext-jms.xml:
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'connectionFactory' defined in class path resource [spring/applicationContext-jms.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
那么针对上述两种解决思路,我做了下面的两种方式验证,并且都取得了成功!
验证思路与解决结果:
验证思路一:注释掉mq的连接池配置,让Spring直接使用ActiveMQ的原厂家工厂bean完成整合下图是核心操作:
org.apache.activemq activemq-all 5.10.0 org.apache.activemq activemq-pool 5.15.8
cd ..\common\
mvn clean install
安装成功后的标识:
进入admin模块,启动项目:
cd ..\admin
mvn jetty:run
在父子聚合,中间件繁多的项目中经常会遇到坑,驱动之间不兼容会是常有的事,遇到问题应该先学会看异常,然后分析具体错误!
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流