Apache Camel启动报错:无法访问org.apache.camel.spi.ResourceAware
解决Apache Camel启动报错"cannot access org.apache.camel.spi.ResourceAware"
问题原因
- 依赖版本严重不兼容:项目使用Camel 4.0.0-M2(里程碑预览版),但手动指定
camel-kafka依赖为3.4.0,跨大版本的依赖组合导致类冲突,缺失必要的SPI类。 - 硬写版本引发依赖冲突:部分Spring相关依赖(如
spring-webmvc、spring-boot-actuator-autoconfigure等)手动指定了与Spring Boot 3.1.0 BOM不一致的版本,破坏了依赖版本一致性,引发类加载异常。 - Camel里程碑版本不稳定:4.0.0-M2是未正式发布的预览版本,类结构可能存在变更或缺失,
org.apache.camel.spi.ResourceAware可能已被移除或重构到其他包中。
修复步骤
1. 升级Camel至正式稳定版
修改dependencyManagement中的Camel BOM版本为正式稳定版(如4.0.0或更高):
<dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-spring-boot-bom</artifactId> <version>4.0.0</version> <type>pom</type> <scope>import</scope> </dependency>
2. 修复Camel Kafka依赖
移除手动指定版本的camel-kafka,改用starter依赖,让BOM自动管理版本:
<!-- 替换原有的camel-kafka依赖 --> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-kafka-starter</artifactId> </dependency>
3. 移除手动指定版本的Spring相关依赖
删除以下硬写版本的依赖,依赖版本由Spring Boot BOM自动管理:
<!-- 删除这些依赖 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>6.0.8</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-actuator-autoconfigure</artifactId> <version>3.0.6</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>6.0.8</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>6.0.3</version> </dependency>
4. 清理并重新构建项目
执行Maven命令清理依赖并重新构建:
mvn clean install -U
之后在IntelliJ中执行File -> Invalidate Caches...并重启IDE,确保依赖完全同步。
内容的提问来源于stack exchange,提问作者MbaiMburu
相关产品推荐
相关产品推荐

