0

There is SpringBoot 2.1.4.RELEASE application with spring-cloud-starter-netflix-ribbon 2.1.1.RELEASE dependency.

Trying to run spring integration test (using @SpringBootTest) during test application startup such an exception is thrown: Caused by: java.lang.ClassNotFoundException:com.netflix.config.CachedDynamicIntProperty

Maven cloud dependencies used in project:

<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>

Test property file:

feign.hystrix.enabled=true eureka.client.enabled=false ribbon.eureka.enabled=false some-my-mocked-service.ribbon.listOfServers=localhost:${mocked.port}

Exception:

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)
mate00
  • 2,727
  • 5
  • 26
  • 34
Alex
  • 181
  • 3
  • 6
  • Are you sure that this is really the complete stacktrace? – the hand of NOD May 15 '19 at 11:26
  • No, the initial stacktrace is much longer but I extract the main reason. Also this piece can be useful: `Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ribbonLoadBalancer' defined in org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration: Bean instantiation via factory method failed; nested exception is ....//exception from question body – Alex May 15 '19 at 11:40
  • Ok, was just asking because sometimes it happens that people do not copy the root cause of the problem but some other parts of the stacktrace. That's more often the case the more autowiring is used :-) – the hand of NOD May 15 '19 at 11:47
  • 1
    Maybe you need the following dependency ``` com.netflix.archaius archaius-core 0.1.4 ``` – the hand of NOD May 15 '19 at 11:49
  • archaius-core didn't help( – Alex May 15 '19 at 14:17
  • Corrupt maven download is my guess – spencergibb May 15 '19 at 16:35
  • You could try to clean everything and make sure that the maven download was successfully (check your jar file in the maven repository). If that's surely not the problem the question is if you use the `spring-boot-maven-plugin` correctly to build your jar file? Could you edit your question and show the complete pom of yours? Because a `NoClassDefFoundError` means usually that something is wrong with your classpath. – the hand of NOD May 16 '19 at 06:23

1 Answers1

1

Run mvn dependency:tree -Dverbose and check the tree for versions conflict - looks like spring-cloud-starter-openfeign and spring-cloud-starter-netflix-ribbon artifacts use different versions of archaius-core.

Vitaly
  • 11
  • 1