BeanCreationException: Error creating bean with name 'configurationPropertiesBeans' defined in class path resource

Viewed 13749

I'm writing a small program for circuit breaker, When running the application it throws exceptions.
springboot versin 2.5.4, Hystrix Version using 2.2.6
BeanCreationException: Error creating bean with name 'configurationPropertiesBeans' defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@659e0bfd]

Pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.4</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.ramgovindhare</groupId>
<artifactId>cricuitbreakerhystrix</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>CricuitBreakerHystrix</name>
<description>firstMicroserviceProject</description>
<properties>
    <java.version>11</java.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-hystrix -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        <version>2.2.8.RELEASE</version> <--- **See this**
    </dependency>
    
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

CricuitBreakerHystrixApplication.java

@SpringBootApplication
@EnableCircuitBreaker
public class CricuitBreakerHystrixApplication {

    public static void main(String[] args) {
        SpringApplication.run(CricuitBreakerHystrixApplication.class, args);
    }
}

Controller class

@RestController
public class CricutiBreakerHystrixController {
    
    @GetMapping("/process")
    @HystrixCommand(fallbackMethod = "doWork")
    public String doProcess() {
        String response = "This msg come for processes";
        int i = 10 / 0;
        return response;
    }
    
    public String doWork() {
        return "This msg coming from doWork()...!!";
    }
}
2 Answers

Just add spring-cloud-dependencies to dependencyManagement block:

<properties>
    <spring.cloud-version>2020.0.3</spring.cloud-version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring.cloud-version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Corresponding version of spring-cloud can be find here

The spring boot version and spring cloud version should be matched in strict accordance with the official version. Link to the official website:spring-cloud Release train Spring Boot compatibility

Related