构建基于JMS实现远程访问时,抛出如下异常:
Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: Forbidden class org.springframework.remoting.support.RemoteInvocation! 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.
activeMQ针对对象的传输有白名单限制(即使你的类实现了序列化借口也会报错),需要将你类所在的包加入白名单。在接受的时候将activeMQConnection.setTrustAllPackages(true);设置为true,(默认的是fales)。
ActiveMQ的ObjectMessage依赖于Java的序列化和反序列化,但是这个过程被认为是不安全的。所以ActiveMQ就强制用户使用完整路径的ObjectMessages来进行交换。
如果你需要使用自定义的ObjectMessage,就要把这个ObjectMessage类添加到应用中。
解决方法 :
简单的解决办法
在消息队列的客户端(即应用代码里),添加如下代码即可:
1. 使所有的类都能够被传输
创建ActiveMQConnectionFactory是设置所有package下的对像都是安全的,如下:
activeMQConnectionFactory.setTrustAllPackages( true );
2.使指定的包里的类能够被传输,如下:
factory.setTrustedPackages(new ArrayList(Arrays.asList("org.apache.activemq.test,org.apache.camel.test".split(","))));