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

Spring应用升级Camel至3.18.0时Bean创建失败问题求助

解决Camel 3.0.0升级至3.18.0时的NoSuchFieldError: log错误

错误根源分析

出现java.lang.NoSuchFieldError: log的核心原因是依赖版本不兼容或冲突,具体问题点包括:

  • 单个Camel组件版本不一致:camel-properties仍使用旧版本3.0.0-RC1,与其他3.18.0版本的Camel组件存在类结构差异
  • 重复引入BOM:同时添加camel-spring-boot-bom和camel-bom,导致依赖版本管理混乱
  • 手动指定的Jetty版本过低:Camel 3.18.0依赖的Jetty版本与项目中硬编码的9.4.21不兼容

具体修复步骤

1. 统一所有Camel组件版本

将camel-properties的版本改为3.18.0,或直接省略版本号(由BOM自动管理):

// 替换旧的依赖行
implementation 'org.apache.camel:camel-properties:3.18.0'
// 更优方式:依赖BOM自动管理版本
// implementation 'org.apache.camel:camel-properties'

2. 清理重复的BOM依赖

移除camel-bom的直接引入,camel-spring-boot-bom已经包含所有Camel组件的版本定义:

// 删除此行
// implementation 'org.apache.camel:camel-bom:3.18.0'

3. 移除手动指定的Jetty依赖

Camel的camel-jetty组件已经内置了适配版本的Jetty依赖,手动指定的旧版本会引发冲突,直接删除所有org.eclipse.jetty相关依赖:

// 删除以下所有行
// implementation 'org.eclipse.jetty:jetty-server:9.4.21.v20190926'
// implementation 'org.eclipse.jetty:jetty-servlet:9.4.21.v20190926'
// ...(所有Jetty相关依赖)

4. 优化其他冗余依赖(可选)

  • 移除javax.persistence:javax.persistence-api:2.2:Spring Boot的JPA starter已包含该API,避免版本冲突
  • 对于Jackson、Gson等通用依赖,尽量省略版本号,让Spring Boot或Camel的BOM自动适配兼容版本

修改后的完整依赖示例

dependencies {
    implementation platform('org.apache.camel.springboot:camel-spring-boot-bom:3.18.0')
    implementation 'org.apache.camel.springboot:camel-spring-boot-starter'
    implementation 'org.apache.camel:camel-rabbitmq'
    implementation 'org.apache.camel:camel-jackson'
    implementation 'org.apache.camel:camel-gson'
    implementation 'org.apache.camel:camel-jetty'
    implementation 'org.apache.camel:camel-netty'
    implementation 'org.apache.camel:camel-netty-http'
    implementation 'org.apache.camel:camel-swagger-java'
    implementation 'org.apache.camel:camel-jpa'
    implementation 'org.apache.camel:camel-dozer'
    implementation 'org.apache.camel:camel-spring-security'
    implementation 'org.apache.camel:camel-jsonpath'
    implementation 'org.apache.camel:camel-properties'
    implementation('org.apache.camel:camel-core') {
        exclude group: 'org.apache.logging.log4j', module: 'log4j-core'
    }

    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'com.zaxxer:HikariCP:3.3.1'
    implementation 'org.postgresql:postgresql:42.2.8'
    implementation 'com.vladmihalcea:hibernate-types-52:1.0.0'
    implementation 'io.jsonwebtoken:jjwt:0.9.1'
    implementation 'org.apache.commons:commons-lang3:3.9'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'io.swagger:swagger-annotations:1.5.23'
    implementation 'org.apache.commons:commons-collections4:4.4'
    implementation 'javax.validation:validation-api:2.0.1.Final'
    implementation 'org.hibernate.validator:hibernate-validator:6.0.13.Final'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'junit:junit:4.13.1'
}

验证步骤

执行gradle dependencies命令检查依赖树,确认所有Camel组件版本统一为3.18.0,无冲突版本后重启应用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 05:25:37