我創建使用JMS通信的兩個springboot服務器&客戶端應用程序,一切工作正常釋放5.12.1
的ActiveMQ的,但只要我更新到5.12.3
版本,我發現了以下錯誤:SpringBoot + ActiveMQ - 如何設置可信軟件包?
org.springframework.jms.support.converter.MessageConversionException: Could not convert JMS message; nested exception is javax.jms.JMSException: Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: Forbidden class MyClass! 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.
我接着提供了the URL,我發現我的問題與ActiveMQ的5.12.2
版本中實現的新安全性有關,我知道我可以通過定義可信軟件包來修復它,但我不知道在我的SpringBoot項目中放置這種配置的位置。
我正在對客戶端和服務器的JMS隊列進行唯一引用,在application.properties中設置它的URI,並在我的「主」類上啓用JMS,並且這是我在獨立代理上的配置:
@Configuration
@ConfigurationProperties(prefix = "activemq")
public class BrokerConfiguration {
/**
* Defaults to TCP 10000
*/
private String connectorURI = "tcp://0.0.0.0:10000";
private String kahaDBDataDir = "../../data/activemq";
public String getConnectorURI() {
return connectorURI;
}
public void setConnectorURI(String connectorURI) {
this.connectorURI = connectorURI;
}
public String getKahaDBDataDir() {
return kahaDBDataDir;
}
public void setKahaDBDataDir(String kahaDBDataDir) {
this.kahaDBDataDir = kahaDBDataDir;
}
@Bean(initMethod = "start", destroyMethod = "stop")
public BrokerService broker() throws Exception {
KahaDBPersistenceAdapter persistenceAdapter = new KahaDBPersistenceAdapter();
persistenceAdapter.setDirectory(new File(kahaDBDataDir));
final BrokerService broker = new BrokerService();
broker.addConnector(getConnectorURI());
broker.setPersistent(true);
broker.setPersistenceAdapter(persistenceAdapter);
broker.setShutdownHooks(Collections.<Runnable> singletonList(new SpringContextHook()));
broker.setUseJmx(false);
final ManagementContext managementContext = new ManagementContext();
managementContext.setCreateConnector(true);
broker.setManagementContext(managementContext);
return broker;
}
}
所以我想知道我應該在哪裏指定可信軟件包。
謝謝:)
謝謝:)我不得不編輯你的答案,因爲'setTrustedPackage'只需要'名單'爲參數,而不是一個'String'。 –
AntoineB
Doh!對不起,當然是。 ActiveMQConnectionFactory也有一個setTrustAllPackages(boolean)方法,所以你不必單獨設置它們。 –