【问题标题】:Spring Boot and ActiveMQ: Ignores broker-url and uses default localhost:61616Spring Boot 和 ActiveMQ:忽略 broker-url 并使用默认 localhost:61616
【发布时间】:2018-04-09 08:32:19
【问题描述】:

我正在使用 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,即使那不是我定义的 url。

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

我该如何解决这个问题?

【问题讨论】:

  • 您必须在其他地方有一些冲突的配置设置,因为默认情况下使用 URL vm://localhost?broker.persistent=false 的内存代理。
  • 您是在使用 actvemq 启动器还是只是一个依赖项?还要确保您没有运行错误的配置文件,因为它会从其他配置文件 application-test.properties、application-dev.properties 等获取属性。另一个原因可能是系统属性覆盖了 application.properties 中的属性
  • 嗨@AndyWilkinson 我不认为默认是内存,因为它需要额外的依赖。我在项目中没有任何其他设置
  • 嗨@DanyloZatorsky 我刚刚在帖子中添加了activemq 依赖项。我没有使用启动器,我有一个 application.properties。我也没有设置任何系统属性

标签: java spring-boot activemq


【解决方案1】:

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

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

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 2013-01-12
    • 2015-10-14
    • 2016-06-08
    • 2019-08-17
    • 2015-08-03
    • 1970-01-01
    • 2015-08-08
    • 2011-04-09
    • 2013-10-06
    相关资源
    最近更新 更多