BeanCreationException:创建类路径资源中定义的名为“configurationPropertiesBeans”的 bean 时出错

Ng *_*rma 6 java spring spring-boot hystrix

我正在为断路器编写一个小程序,运行该应用程序时会抛出异常。
springboot 版本 2.5.4,Hystrix 版本使用2.2.6
BeanCreationException:创建类路径资源 [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class] 中定义的名为“configurationPropertiesBeans”的 bean 时出错:合并 bean 定义的后处理失败;嵌套异常是 java.lang.IllegalStateException:无法从 ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@659e0bfd] 内省类 [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans]

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>
Run Code Online (Sandbox Code Playgroud)

CriuitBreakerHystrixApplication.java

@SpringBootApplication
@EnableCircuitBreaker
public class CricuitBreakerHystrixApplication {

    public static void main(String[] args) {
        SpringApplication.run(CricuitBreakerHystrixApplication.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

控制器类

@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()...!!";
    }
}
Run Code Online (Sandbox Code Playgroud)

Ale*_*pov 10

只需将 spring-cloud-dependencies 添加到 dependencyManagement 块即可:

<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>
Run Code Online (Sandbox Code Playgroud)

对应的spring-cloud版本可以在这里找到


袁文涛*_*袁文涛 10

spring boot版本和spring cloud版本要严格按照官方版本进行匹配。官网链接:spring-cloud 发布火车 Spring Boot 兼容性