简体   繁体   中英

application.yaml spring.activemq.broker-url not set

I'm trying to set my spring app to listen to a JMS queue. I try to set the broker-url in my application.yml but it always seems to default back to "localhost:61616". The application.yml file is loaded from another application, but I don't think that matters since other properties in the file are read (the name of the queues for example)

Here is the message I get :

o.a.a.t.failover.FailoverTransport;Failed to connect to [tcp://localhost:61616] after: 40 attempt(s) continuing to retry.

What I tried

I've tried following the answer to this question : Camel ActiveMQ + Spring boot not reading spring activemq configurations Which is my exact issue

But when I try adding the dependency and creating that class I get this error :

Parameter 0 of method createComponent in xxx.xxxxx.xxxx.configuration.ActiveMQComponentConfig required a bean of type 'javax.jms.ConnectionFactory' that could not be found.

I'm quite new to Spring boot / ActiveMQ and don't really know what to do about this.

Here's the relevant part of my pom.xml

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath />
</parent>

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-spring-boot-starter</artifactId>
    <version>${camel.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-camel</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-broker</artifactId>
        </exclusion>
    </exclusions>
</dependency>

And my application.yml :

spring:
  aop:
    proxy-target-class: true
  cache:
    ehcache:
      config: classpath:ehcache.xml
  activemq:
    broker-url: tcp://foo:12345
    pool:
      enabled: true
      max-connections: 5

Any help would be greatly appreciated, I already spent a fair amount of time on this and not making any progress

This is what I ended up doing to get it to work again. I still don't know why Spring's autoconfig stopped working but that solved it

@Configuration
public class JmsConfig {

    @Value("${spring.activemq.broker-url}")
    String BROKER_URL;
    @Value("${spring.activemq.user}")
    String BROKER_USERNAME;
    @Value("${spring.activemq.password}")
    String BROKER_PASSWORD;

    @Bean
    public ActiveMQConnectionFactory connectionFactory(){
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
        connectionFactory.setBrokerURL(BROKER_URL);
        connectionFactory.setUserName(BROKER_USERNAME);
        connectionFactory.setPassword(BROKER_PASSWORD);
        return connectionFactory;
    }

    @Bean
    public JmsTemplate jmsTemplate(){
        JmsTemplate template = new JmsTemplate();
        template.setConnectionFactory(connectionFactory());
        return template;
    }

    @Bean
    public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory());
        factory.setConcurrency("1-1");
        return factory;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM