添加feign-client依赖后Spring Boot应用启动失败该如何处理?
问题根因
- 你引入的
spring-cloud-starter-feign:1.4.7.RELEASE属于Spring Cloud Edgware版本族,该版本仅适配Spring Boot 1.5.x系列,和你使用的Spring Boot 2.4.x、2.5.x版本完全不兼容。 - Spring Boot 2.0版本重构了web相关自动配置类的包路径,旧版Feign Starter强依赖的
org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.class在2.0及以上版本中已经被迁移到org.springframework.boot.autoconfigure.web.servlet路径下,旧版本组件检索原路径的类自然会抛出文件不存在的异常。
解决方案
- 废弃已停止维护的旧版Feign Starter坐标,改用Spring Cloud官方后续迭代的OpenFeign Starter。首先在pom.xml中引入和你当前Spring Boot版本匹配的Spring Cloud依赖管理:
- Spring Boot 2.4.x对应Spring Cloud 2020.0.x版本族
- Spring Boot 2.5.x对应Spring Cloud 2021.0.x版本族
以Spring Boot 2.5.x为例,依赖管理配置如下:
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>2021.0.5</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
- 替换原有Feign依赖为如下坐标,无需手动指定版本,由依赖管理统一控制版本匹配,避免兼容问题:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency>
内容的提问来源于stack exchange,提问作者Baggio
相关产品推荐
相关产品推荐

