我正在创建两个springboot服务器&客户端应用程序使用JMS进行通信,并且针对activemq的版本Dim HdrRow as range
Dim Cl as Range
Set HdrRow = ActiveSheet.UsedRange
Set HdrRow = HdrRow.Row(1) 'assuming row 1 of the data contains headers
For Each Cl In HdrRow.cells
If Instr(lCase(Cl.Value), "date") > 0 then 'This column has "date" in the header text
enter code here
Next Cl
一切正常,但是一旦我更新到5.12.1
版本,我就会收到以下错误:
5.12.3
我继续提供the URL,我发现我的问题与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.
版本中实现的新安全性有关,我知道我可以通过定义可信包,但我不知道在SpringBoot项目中将这样的配置放在哪里。
我在客户端和服务器中对JMS队列的唯一引用是在application.properties中设置它的URI并在我的" main"上启用JMS。使用5.12.2
的类,以及我在单独的代理上的配置:
@EnableJms
所以我想知道我应该在哪里指定受信任的套餐。
谢谢:)
答案 0 :(得分:18)
您可以在application.properties
中设置以下弹簧启动属性之一来设置受信任的包。
spring.activemq.packages.trust-all=true
或
spring.activemq.packages.trusted=<package1>,<package2>,<package3>
答案 1 :(得分:15)
添加以下bean:
@Bean
public ActiveMQConnectionFactory activeMQConnectionFactory() {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("your broker URL");
factory.setTrustedPackages(Arrays.asList("com.my.package"));
return factory;
}
为下一个版本添加了通过配置属性执行此操作的功能: https://github.com/spring-projects/spring-boot/issues/5631
答案 2 :(得分:3)
方法:public void setTrustedPackages(List<String> trustedPackages)
描述:添加发送和接收Message
对象中使用的所有包。
代码:connectionFactory.setTrustedPackages(Arrays.asList("org.api","java.util"))
实施守则:
private static final String DEFAULT_BROKER_URL = "tcp://localhost:61616";
private static final String RESPONSE_QUEUE = "api-response";
@Bean
public ActiveMQConnectionFactory connectionFactory(){
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connectionFactory.setBrokerURL(DEFAULT_BROKER_URL);
connectionFactory.setTrustedPackages(Arrays.asList("org.api","java.util"));
return connectionFactory;
}
@Bean
public JmsTemplate jmsTemplate(){
JmsTemplate template = new JmsTemplate();
template.setConnectionFactory(connectionFactory());
template.setDefaultDestinationName(RESPONSE_QUEUE);
return template;
}
答案 3 :(得分:1)
我正在将Java_opts设置如下,并传递给java命令及其对我有用。
JAVA_OPTS=-Xmx256M -Xms16M -Dorg.apache.activemq.SERIALIZABLE_PACKAGES=*
java $JAVA_OPTS -Dapp.config.location=/data/config -jar <your_jar>.jar --spring.config.location=file:/data/config/<your config file path>.yml
答案 4 :(得分:0)
是的我在新版本中找到了它的配置
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
spring:
profiles:
active: @profileActive@
cache:
ehcache:
config: ehcache.xml
activemq:
packages:
trusted: com.stylrplus.api.model
答案 5 :(得分:0)
如果仍然有人在寻找答案,以下摘录对我有用
@Bean
public ActiveMQConnectionFactory connectionFactory() {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connectionFactory.setBrokerURL(BROKER_URL);
connectionFactory.setPassword(BROKER_USERNAME);
connectionFactory.setUserName(BROKER_PASSWORD);
connectionFactory.setTrustAllPackages(true); // all packages are considered as trusted
//connectionFactory.setTrustedPackages(Arrays.asList("com.my.package")); // selected packages
return connectionFactory;
}