Spring Boot ActiveMQ

标签 spring spring-boot activemq

在我的 Spring Boot 1.4.0.BUILD-SNAPSHOT 应用程序中,为了修复 ActiveMQ 安全问题:

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.

我必须添加以下参数(我想允许所有类)

-Dorg.apache.activemq.SERIALIZABLE_PACKAGES="*"

到应用程序 VM 参数。

是否可以通过 application.properties 或我的 Spring Boot 应用程序内部的其他方式提供此参数?

最佳答案

可以在spring boot应用中设置。在配置类中,您需要获取 ActiveMQConnectionFactory 的句柄并设置它们,如下所示:

@Inject
private ActiveMQConnectionFactory connectionFactory;

private void addTrustedPackage(){
     final List<String> trustedPackageList = new ArrayList<>(connectionFactory.getTrustedPackages());
     trustedPackageList.add("the packages that you want to add");
     connectionFactory.setTrustedPackages(trustedPackageList);
}

您需要获取现有包列表并添加到其中的原因是因为它包含基础包,如 java.lang 等。

您也可以使用

在 application.properties 文件中设置这些
spring.activemq.packages.trust-all=false # Trust all packages.
spring.activemq.packages.trusted= # Comma-separated list of specific packages to trust (when not trusting all packages).

引用:http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/html/common-application-properties.html

关于Spring Boot ActiveMQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38124589/

相关文章:

java - 如何配置 Spring 和 SLF4J 以便获得日志记录?

java - 用于排除注释的 AspectJ 切入点

java - 在spring中获取工厂类的servletcontext

mysql - 如何在 Spring Boot 中使用 Thymeleaf 保存角色?

node.js - Log4j JMS 附加程序向 STOMP 客户端发送空消息

java - Spring JMS 消息监听器容器

java - 无法知道 JdbcTemplate 支持出了什么问题

java - Spring-boot:不能使用持久性

java - Rest API 中的 JWT token 传递

java - 为什么 Activemq-web-console 无法在 Fuse Servicemix 4.3.0-fuse-02-00 上运行?