首先声明spingboot 版本为2.3.1,activemq版本受springboot管理(2.3.1)。
报错出现在生产者发送实体类对象时出现的,报错信息显示无法构建。
ObjectMessage objectMessage = session.createObjectMessage(message);
messageProducer.send(message);
javax.jms.JMSException: Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: Forbidden class com.xx.xx.entity.xxx! 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.
Caused by: java.lang.ClassNotFoundException: Forbidden class com.xx.xx.entity.xxx! 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.
按照以下操作进行修改:
1.报错信息中的“http://activemq.apache.org/objectmessage.html”提示将-Dorg.apache.activemq.SERIALIZABLE_PACKAGES=*加入到activemq/bin/下的env中ACTIVEMQ_OPTS后面
ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS_MEMORY -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=$ACTIVEMQ_CONF/login.config"
2.在application.xml中配置trust-all-packages为true
spring:
activemq:
packages:
trust-all: true
3.在代码中强制使用System.setProperty的trust-package参数为true
但是都不起作用
所以直接硬来吧 ,问题解决
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(userName, password, url);
connectionFactory.setTrustAllPackages(true);
Over