SpringBoot + ActiveMQ - How to set trusted packages?

后端 未结 6 925
既然无缘
既然无缘 2021-02-19 04:47

I\'m creating two springboot server & client applications communicating using JMS, and everything is working fine with the release 5.12.1 for activemq, but as s

相关标签:
6条回答
  • 2021-02-19 05:25

    Add the following bean:

    @Bean
    public ActiveMQConnectionFactory activeMQConnectionFactory() {
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("your broker URL");
        factory.setTrustedPackages(Arrays.asList("com.my.package"));
        return factory;
    }
    

    The ability to do this via a configuration property has been added for the next release: https://github.com/spring-projects/spring-boot/issues/5631

    0 讨论(0)
  • 2021-02-19 05:28

    If any one still looking for an answer, below snippet worked for me

    @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;
    }
    
    0 讨论(0)
  • 2021-02-19 05:32

    I am setting Java_opts something like below and passing to java command and its working for me.

    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
    
    0 讨论(0)
  • 2021-02-19 05:33

    You can just set one of the below spring boot properties in application.properties to set trusted packages.

    spring.activemq.packages.trust-all=true

    or

    spring.activemq.packages.trusted=<package1>,<package2>,<package3>

    0 讨论(0)
  • 2021-02-19 05:38

    Method: public void setTrustedPackages(List<String> trustedPackages)

    Description: add all packages which is used in send and receive Message object.

    Code : connectionFactory.setTrustedPackages(Arrays.asList("org.api","java.util"))

    Implementated Code:

    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;
    }
    
    0 讨论(0)
  • 2021-02-19 05:45

    Yes I found it's config in the new version

    <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
    
    0 讨论(0)
提交回复
热议问题