在我的 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).
关于Spring Boot ActiveMQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38124589/