Spring Boot和ActiveMQ:忽略broker-url并使用默认的localhost:61616

时间:2017-10-27 16:55:52

标签: java spring-boot activemq

我正在使用Spring Boot和ActiveMQ。在application.properties中,我为activemq设置了这样的url:

spring.activemq.broker-url=vm://localhost?broker.persistent=false

正如您所看到的,我正在使用嵌入式代理(在pom中添加了依赖关系)。 这是我的应用程序类:

@SpringBootApplication
@EntityScan(
    basePackageClasses = {ServiceApplication.class, Jsr310JpaConverters.class}
)
@EnableAutoConfiguration
@ServletComponentScan
public class ServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServiceApplication.class, args);
    }

}

这些是pom中与activemq相关的依赖项:

<dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-camel</artifactId>
        <version>5.14.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-pool</artifactId>
        <version>5.14.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-broker</artifactId>
        <version>5.14.5</version>
    </dependency>

我有一个application.properties,我没有不同的配置文件。

但是当我运行应用程序时,我得到了这个日志:

[ActiveMQ Task-1] o.a.a.t.failover.FailoverTransport       : Failed to connect to [tcp://localhost:61616] after: 10 attempt(s) continuing to retry.

它正在尝试连接到tcp:// localhost:61616,即使这不是我定义的网址。

我尝试删除@EnableAutoConfiguration但仍然存在同样的问题。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

您的ActiveMQ客户端不知道spring.activemq.broker-url,因为此属性用于配置spring-boot-starter-activemq。如果您没有此启动器,则不使用此属性进行任何配置。

我建议您浏览以下资源,以便更好地了解如何在项目中设置spring-boot-starter-activemq:

希望它有所帮助!