Active MQ 传输 ObjectMessage 异常

时间:2024-07-25 14:04:02
<bean id="targetConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
<!-- 如果传输的对象是Obeject 这里必须加上这句 否则会导致对象序列化失败 出现classnotfound异常 详细: http://activemq.apache.org/objectmessage.html -->
<property name="trustAllPackages" value="true"/>
</bean>

在消费者接受队消息时,出现异常

javax.jms.JMSException: Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: Forbidden class com.guesslive.admin.common.mail.Mail! This class is not trusted to be serialized as ObjectMessage payload. Please take a look at http://activemq.apache.org/objectmessage.html for more information on how to configure trusted classes.

然后根据提供的地址找了下原因,在 ActiveMQConnectionFactory 中加入参数

<property name="trustAllPackages" value="true"/>

问题解决!