有SpringBoot 2.1.4.RELEASE
个具有spring-cloud-starter-netflix-ribbon 2.1.1.RELEASE依赖性的应用程序。
在测试应用程序启动期间尝试运行spring集成测试(使用@SpringBootTest
),将引发异常:
Caused by: java.lang.ClassNotFoundException:com.netflix.config.CachedDynamicIntProperty
项目中使用的Maven云依赖项:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
</parent>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
测试属性文件:
feign.hystrix.enabled=true
eureka.client.enabled=false
ribbon.eureka.enabled=false
some-my-mocked-service.ribbon.listOfServers=localhost:${mocked.port}
例外:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.loadbalancer.ILoadBalancer]: Factory method 'ribbonLoadBalancer' threw exception; nested exception is java.lang.NoClassDefFoundError: Lcom/netflix/config/CachedDynamicIntProperty;
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)
答案 0 :(得分:0)
运行mvn dependency:tree -Dverbose
并检查树中是否存在版本冲突-看起来像 spring-cloud-starter-openfeign 和 spring-cloud-starter-netflix-ribbon 工件使用不同版本的 archaius-core 。