环境
springboot 2.1.3 + springCloud + RestTemplate + Ribbon + JDK1.8
问题描述
在pom.xml中引入Hystrix后,启动项目失败,pom依赖如下:
报错信息如下:
BeanDefinitionStoreException 和 FileNotFoundException,这是因为ServerPropertiesAutoConfiguration 在springboot 2.x.x中已经废弃,所以找不到该文件。
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.poem.ConsumerApplication]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.class] cannot be opened because it does not exist
解决方法
经过在网上搜索之后锁定问题所在,是因为spring-cloud-starter-hystrix已经弃用了,如下:
https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-hystrix
需要改换使用spring-cloud-starter-netflix-hystrix,如下:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
由于版本适配原因,没有选择最新版本,所以选择了 2.1.0版本。
至此,启动项目成功。