1. 程式人生 > >Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions

Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions

Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'messageListener' threw exception; nested exception is java.lang.IllegalArgumentException: Message listener needs to be of type [javax.jms.MessageListener] or [org.springframework.jms.listener.SessionAwareMessageListener]
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:121)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1514)
    ... 40 more

 

出現這種bug提示說Property 'messageListener'不正常,這時候發現了下面配置寫錯啦

錯誤的配置

<!--這個是主題目的地,釋出訂閱的  文字資訊-->
<bean id="topicdestination" class="org.apache.activemq.command.ActiveMQTopic">
    <constructor-arg value="springjms-productor-topic-demo"/>
</bean>
<!-- 我的監聽類 -->
<bean id="topicConsumer" class="cn.itcast.demo.TopicConsumer"></bean>
<!-- 訊息監聽容器 -->
<bean class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <!--連線工廠-->
    <property name="connectionFactory" ref="SingleconnectionFactory"/>
    <!--訊息消費的目的地-->
    <property name="destination" ref="topicdestination"/>
    <!--訊息的監聽類-->
    <!--<property name="messageListener" ref="topicConsumer" />-->
    <property name="messageListener" value="topicConsumer"/>
</bean>

正確的配置

<!--這個是主題目的地,釋出訂閱的  文字資訊-->
<bean id="topicdestination" class="org.apache.activemq.command.ActiveMQTopic">
    <constructor-arg value="springjms-productor-topic-demo"/>
</bean>
<!-- 我的監聽類 -->
<bean id="topicConsumer" class="cn.itcast.demo.TopicConsumer"></bean>
<!-- 訊息監聽容器 -->
<bean class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <!--連線工廠-->
    <property name="connectionFactory" ref="SingleconnectionFactory"/>
    <!--訊息消費的目的地-->
    <property name="destination" ref="topicdestination"/>
    <!--訊息的監聽類-->
    <property name="messageListener" ref="topicConsumer"/>
</bean>

property裡面都是ref才是正確的啊,寫成value就錯了