1、org.springframework.jms.support.converter.MessageConversionException: Cannot convert object of type [] to JMS message
Request processing failed; nested exception is org.springframework.jms.support.converter.MessageConversionException: Cannot convert object of type [] to JMS message. Supported message payloads are: String, byte array, Map<String,?>, Serializable object.] with root cause
org.springframework.jms.support.converter.MessageConversionException: Cannot convert object of type [] to JMS message. Supported message payloads are: String, byte array, Map<String,?>, Serializable object.
通常情况下,mq支持String, byte数组, Map<String,?>, 序列化对象这4种类型的传输。对于自定义类(User),还必须要实现序列化接口:
User.java
public class User implements Serializable {
private String userName;
private Integer passwoed;
public User(String userName, Integer passwoed) {
this.userName = userName;
this.passwoed = passwoed;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Integer getPasswoed() {
return passwoed;
}
public void setPasswoed(Integer passwoed) {
this.passwoed = passwoed;
}
@Override
public String toString() {
String s = "name:" + this.getUserName() + ",password:" + this.getPasswoed();
return s;
}
}
2、javax.jms.JMSException: Failed to build body from content.
javax.jms.JMSException: Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: Forbidden class User! 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.
貌似刚解决第一个,第二个问题就来了。怪我!!
这个错误是说,User类并不被mq允许,解决办法也简单,就是在mq的xml文件中,找到<amq:connectionFactory>标签,加入一个属性:trustAllPackages=“true”(直接写死得了)
<!--设置activeMq的属性,包括用户名密码-->
<amq:connectionFactory id="amqConnectionFactory" brokerURL="${spring.activemq.broker-url}"
userName="${spring.activemq.user}" password="${spring.activemq.password}" trustAllPackages="true"/>
问题迎刃而解
3、Attribute ‘trustAllPackages’ is not allowed to appear in element ‘amq:connectionFactory’
这个问题是在第二个基础上产生的,笔者目前还没解决。干脆不用对象了,实在不行用JSON吧。