我正在编写一个小程序用于断路器。运行应用程序时,它会抛出异常。
使用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] 的Class [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>
CricuitBreakerHystrixApplication.java
@SpringBootApplication
@EnableCircuitBreaker
public class CricuitBreakerHystrixApplication {
public static void main(String[] args) {
SpringApplication.run(CricuitBreakerHystrixApplication.class, args);
}
}
控制器类
@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()...!!";
}
}