jms 初始化报错 java.lang.reflect.MalformedParameterizedTypeException

系统:win7

环境:maven3.0.5

jre:JavaSE-1.6

运行环境:tomcat

涉及到的主要 jar 包:activemq-all-5.8.0.jar,activemq-pool-5.8.0.jar,commons-pool-1.6.jar

引入 jms:applicationContext-jms.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"
default-lazy-init="false" default-autowire="byName">


<!-- 消息队列工厂 added by xiluhua 2014-07-31->
<bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://10.1.15.22:61616" />
</bean>
</property>
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="jmsFactory" />
<property name="receiveTimeout" value="1000" />
<property name="messageConverter">
<bean
class="org.springframework.jms.support.converter.SimpleMessageConverter" />
</property>
<property name="deliveryMode" value="2" /> <!-- 发送模式 DeliveryMode.NON_PERSISTENT=1: 非持久 ; DeliveryMode.PERSISTENT=2: 持久 -->
<property name="sessionAcknowledgeMode" value="1" />
</bean>
</beans>

1,spring 初始化 jmsFactory 报错 java.lang.reflect.MalformedParameterizedTypeException

刚开始未引入 commons-pool-1.6.jar,而使用了项目现成的 commons-pool-1.3.jar,结果由于 1.3 不支持泛型,产生以上错误。

2,注意使用 maven 插件版的 tomcat 依赖 jar 包不可以使用 <scope>system</scope>, 这种方式编译能通过,但在运行是容器加载不到 commons-pool-1.6.jar,必须上传到本地 repository 或项目所在私服。否则会产生 Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool.KeyedPoolableObjectFactory

 感谢成家荣的专栏给予的帮助:http://blog.csdn.net/yunye114105/article/details/15340677。