You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Spring Boot至3.0.3后ActiveMQ BrokerService测试代码失效问题

关于Spring Boot 3.x 移除ActiveMQ Classic支持的解决方案

核心结论

  • Spring Boot 3.x 系列完全移除了对Apache ActiveMQ Classic的官方starter支持,Maven中央仓库不会再发布3.x版本的spring-boot-starter-activemq,这是官方明确的废弃决定。
  • 官方优先推荐迁移至ActiveMQ Artemis——它是Apache ActiveMQ的下一代消息 broker,Spring Boot 3.x 提供了完整的spring-boot-starter-artemis starter支持,也是当前官方文档中重点维护的JMS实现。

针对你的测试代码的迁移方案

你当前的代码使用了ActiveMQ Classic的嵌入式BrokerService,对应Artemis的嵌入式实现可以这样替换:

替换后的配置代码

import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ;

@Slf4j
public class MqTestConfiguration {

    public static final String BROKER_URL = "tcp://localhost:61616";

    public static EmbeddedActiveMQ getBrokerServiceInstance() throws Exception {
        EmbeddedActiveMQ embeddedActiveMQ = new EmbeddedActiveMQ();
        // 禁用持久化,对应原代码的setPersistent(false)
        embeddedActiveMQ.setPersistent(false);
        // 禁用JMX,对应原代码的setUseJmx(false)
        embeddedActiveMQ.setJmxManagementEnabled(false);
        // 添加TCP连接器
        embeddedActiveMQ.addConnectorConfiguration("tcp-connector", BROKER_URL);
        return embeddedActiveMQ;
    }
}

通用迁移步骤(官方指导核心要点)

  1. 替换依赖:移除spring-boot-starter-activemq,添加spring-boot-starter-artemis依赖。
  2. 配置调整:
    • 原ActiveMQ Classic的配置前缀spring.activemq.*替换为spring.artemis.*,比如spring.artemis.broker-url、spring.artemis.user等。
  3. API适配:
    • 若使用了Classic特有的API(如ActiveMQConnectionFactory),替换为Artemis的ActiveMQJMSConnectionFactory。
    • 嵌入式broker从BrokerService切换为EmbeddedActiveMQ(如上述示例)。
  4. 特性兼容:Artemis兼容大部分Classic的核心JMS特性,但若使用了Classic专属的高级特性(如某些自定义拦截器、特定存储策略),需要参考Artemis官方文档做对应调整。

内容的提问来源于stack exchange,提问作者Keith Bennett

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 13:07:31