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

Spring Boot 2集成Apache Camel启动报错:XmlCamelContextConfigurer缺失

解决Spring Boot + Camel启动时XmlCamelContextConfigurer类找不到的问题

我帮你排查下这个启动错误的问题——你遇到的ClassNotFoundException: org.apache.camel.spring.spi.XmlCamelContextConfigurer,根源是依赖重复引入且版本不兼容。

问题原因

在使用Camel Spring Boot Starter的时候,你额外添加了camel-spring依赖,但实际上camel-spring-boot-starter已经包含了与Spring整合所需的所有必要组件,重复引入反而会导致类加载冲突:Camel Spring Boot的整合逻辑并不需要XmlCamelContextConfigurer这个类,而多余的camel-spring依赖会让类加载器尝试去加载它,最终找不到抛出异常。

修复步骤

  1. 清理多余依赖
    直接从你的pom.xml中删除camel-spring依赖,保留核心的两个依赖即可。修改后的pom依赖如下:

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
            <version>2.24.0</version>
        </dependency>
    </dependencies>
    
  2. 确认版本兼容性
    你的Spring Boot 2.2.6.RELEASE和Camel 2.24.0是完全兼容的(Camel 2.24.x系列就是为Spring Boot 2.2.x版本适配的),所以版本不需要调整。

  3. 验证基础路由
    你用@Component标注RouteBuilder的方式是正确的,Spring Boot会自动扫描并注册这个路由。修复依赖后,你的测试路由from("timer:foo").to("log:bar")应该能正常启动,控制台会每隔一秒输出日志(默认timer频率)。

后续扩展到你的业务需求

等基础路由正常运行后,你可以替换成ActiveMQ监听+REST POST的逻辑,比如:

@Override
public void configure() throws Exception {
    // 监听ActiveMQ队列
    from("activemq:queue:your-business-queue")
        .log("Received message from ActiveMQ: ${body}")
        // 调用REST POST接口
        .to("http://your-rest-service-url/path?httpMethod=POST");
}

注意:如果要使用ActiveMQ组件,还需要添加对应的starter依赖:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-activemq-starter</artifactId>
    <version>2.24.0</version>
</dependency>

按照上述步骤修改后,重新启动应用应该就能正常运行了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 11:37:52