一、pom.xml需要引入的依赖
二、项目开启熔断器开关
2.1 注解方式
2.2 xml方式
三、依赖类缺失问题
四、版本匹配安全检查问题
五、测试验证
六、结论
一、pom.xml需要引入的依赖
pom.xml
<!-- springboot升级到2.6.7,同样适用于2.7.0,2.7.18等 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!-- hystrix需要升级到2.x以上版本 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.2.10.RELEASE</version>
</dependency>
<!-- 升级后运行时缺失依赖 -->
<dependency>
<groupId>org.hdrhistogram</groupId>
<artifactId>HdrHistogram</artifactId>
<version>2.1.12</version>
</dependency>
二、项目开启熔断器开关
2.1 注解方式
@EnableHystrix
@EnableCircuitBreaker
注:项目启动类中加上以上注解,以上两者取其一即可;
2.2 xml方式
以上注解方式底层就是实例化此类:
三、依赖类缺失问题
此时运行项目将报以下错误:
errpr.log
D:\JDK\jdk1.8\bin\java.exe -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:55698,suspend=y,server=n -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -javaagent:C:\Users\mingming.chen\AppData\Local\JetBrains\IntelliJIdea2021.3\captureAgent\debugger-agent.jar -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dfile.encoding=UTF-8 -classpath "D:\JDK\jdk1.8\jre\lib\charsets.jar;D:\JDK\jdk1.8\jre\lib\deploy.jar;D:\JDK\jdk1.8\jre\lib\ext\access-bridge-64.jar;D:\JDK\jdk1.8\jre\lib\ext\cldrdata.jar;D:\JDK\jdk1.8\jre\lib\ext\dnsns.jar;D:\JDK\jdk1.8\jre\lib\ext\jaccess.jar;D:\JDK\jdk1.8\jre\lib\ext\jfxrt.jar;D:\JDK\jdk1.8\jre\lib\ext\localedata.jar;D:\JDK\jdk1.8\jre\lib\ext\nashorn.jar;D:\JDK\jdk1.8\jre\lib\ext\sunec.jar;D:\JDK\jdk1.8\jre\lib\ext\sunjce_provider.jar;D:\JDK\jdk1.8\jre\lib\ext\sunmscapi.jar;D:\JDK\jdk1.8\jre\lib\ext\sunpkcs11.jar;D:\JDK\jdk1.8\jre\lib\ext\zipfs.jar;D:\JDK\jdk1.8\jre\lib\javaws.jar;D:\JDK\jdk1.8\jre\lib\jce.jar;D:\JDK\jdk1.8\jre\lib\jfr.jar;D:\JDK\jdk1.8\jre\lib\jfxswt.jar;D:\JDK\jdk1.8\jre\lib\jsse.jar;D:\JDK\jdk1.8\jre\lib\management-agent.jar;D:\JDK\jdk1.8\jre\lib\plugin.jar;D:\JDK\jdk1.8\jre\lib\resources.jar;D:\JDK\jdk1.8\jre\lib\rt.jar;D:\LocalReposition\oherproject\testProject\PersonalAssistant\target\classes;D:\MAVEN\MavenRepository\org\springframework\boot\spring-boot-starter\2.6.7\spring-boot-starter-2.6.7.jar;D:\MAVEN\MavenRepository\org\springframework\boot\spring-boot\2.6.7\spring-boot-2.6.7.jar;D:\MAVEN\MavenRepository\org\springframework\spring-context\5.3.19\spring-context-5.3.19.jar;D:\MAVEN\MavenRepository\org\springframework\boot\spring-boot-autoconfigure\2.6.7\spring-boot-autoconfigure-2.6.7.jar;D:\MAVEN\MavenRepository\org\springframework\boot\spring-boot-starter-logging\2.6.7\spring-boot-starter-logging-2.6.7.jar;D:\MAVEN\MavenRepository\ch\qos\logback\logback-classic\1.2.11\logback-classic-1.2.11.jar;D:\MAVEN\MavenRepository\ch\qos\logback\logback-core\1.2.11\logback-core-1.2.11.jar;D:\MAVEN\MavenRepository\org\apache\logging\log4j\log4j-to-slf4j\2.17.2\log4j-to-slf4j-2.17.2.jar;D:\MAVEN\MavenRepository\org\slf4j\jul-to-slf4j\1.7.36\jul-to-slf4j-1.7.36.jar;D:\MAVEN\MavenRepository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\MAVEN\MavenRepository\org\springframework\spring-core\5.3.19\spring-core-5.3.19.jar;D:\MAVEN\MavenRepository\org\springframework\spring-jcl\5.3.19\spring-jcl-5.3.19.jar;D:\MAVEN\MavenRepository\org\yaml\snakeyaml\1.29\snakeyaml-1.29.jar;D:\MAVEN\MavenRepository\org\springframework\boot\spring-boot-starter-test\2.6.7\spring-boot-starter-test-2.6.7.jar;D:\MAVEN\MavenRepository\org\springframework\boot\spring-boot-test\2.6.7\spring-boot-test-2.6.7.jar;D:\MAVEN\MavenRepository\org\springframework\boot\spring-boot-test-autoconfigure\2.6.7\spring-boot-test-autoconfigure-2.6.7.jar;D:\MAVEN\MavenRepository\com\jayway\jsonpath\json-path\2.6.0\json-path-2.6.0.jar;D:\MAVEN\MavenRepository\net\minidev\json-smart\2.4.8\json-smart-2.4.8.jar;D:\MAVEN\MavenRepository\net\minidev\accessors-smart\2.4.8\accessors-smart-2.4.8.jar;D:\MAVEN\MavenRepository\jakarta\xml\bind\jakarta.xml.bind-api\2.3.3\jakarta.xml.bind-api-2.3.3.jar;D:\MAVEN\MavenRepository\jakarta\activation\jakarta.activation-api\1.2.2\jakarta.activation-api-1.2.2.jar;D:\MAVEN\MavenRepository\org\assertj\assertj-core\3.21.0\assertj-core-3.21.0.jar;D:\MAVEN\MavenRepository\org\hamcrest\hamcrest\2.2\hamcrest-2.2.jar;D:\MAVEN\MavenRepository\org\junit\jupiter\junit-jupiter\5.8.2\junit-jupiter-5.8.2.jar;D:\MAVEN\MavenRepository\org\junit\jupiter\junit-jupiter-api\5.8.2\junit-jupiter-api-5.8.2.jar;D:\MAVEN\MavenRepository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;D:\MAVEN\MavenRepository\org\junit\platform\junit-platform-commons\1.8.2\junit-platform-commons-1.8.2.jar;D:\MAVEN\MavenRepository\org\apiguardian\apiguardian-api\1.1.2\apiguardian-api-1.1.2.jar;D:\MAVEN\MavenRepository\org\junit\jupiter\junit-jupiter-params\5.8.2\junit-jupiter-params-5.8.2.jar;D:\MAVEN\MavenRepository\org\junit\jupiter\junit-jupiter-engine\5.8.2\junit-jupiter-engine-5.8.2.jar;D:\MAVEN\MavenRepository\org\junit\platform\junit-platform-engine\1.8.2\junit-platform-engine-1.8.2.jar;D:\MAVEN\MavenRepository\org\mockito\mockito-core\4.0.0\mockito-core-4.0.0.jar;D:\MAVEN\MavenRepository\net\bytebuddy\byte-buddy\1.11.22\byte-buddy-1.11.22.jar;D:\MAVEN\MavenRepository\net\bytebuddy\byte-buddy-agent\1.11.22\byte-buddy-agent-1.11.22.jar;D:\MAVEN\MavenRepository\org\objenesis\objenesis\3.2\objenesis-3.2.jar;D:\MAVEN\MavenRepository\org\mockito\mockito-junit-jupiter\4.0.0\mockito-junit-jupiter-4.0.0.jar;D:\MAVEN\MavenRepository\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;D:\MAVEN\MavenRepository\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;D:\MAVEN\MavenRepository\org\springframework\spring-test\5.3.19\spring-test-5.3.19.jar;D:\MAVEN\MavenRepository\org\xmlunit\xmlunit-core\2.8.4\xmlunit-core-2.8.4.jar;D:\MAVEN\MavenRepository\org\springframework\boot\spring-boot-starter-web\2.6.7\spring-boot-starter-web-2.6.7.jar;D:\MAVEN\MavenRepository\org\springframework\boot\spring-boot-starter-json\2.6.7\spring-boot-starter-json-2.6.7.jar;D:\MAVEN\MavenRepository\com\fasterxml\jackson\core\jackson-databind\2.13.2.1\jackson-databind-2.13.2.1.jar;D:\MAVEN\MavenRepository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.13.2\jackson-datatype-jdk8-2.13.2.jar;D:\MAVEN\MavenRepository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.13.2\jackson-datatype-jsr310-2.13.2.jar;D:\MAVEN\MavenRepository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.13.2\jackson-module-parameter-names-2.13.2.jar;D:\MAVEN\MavenRepository\org\springframework\boot\spring-boot-starter-tomcat\2.6.7\spring-boot-starter-tomcat-2.6.7.jar;D:\MAVEN\MavenRepository\org\apache\tomcat\embed\tomcat-embed-core\9.0.62\tomcat-embed-core-9.0.62.jar;D:\MAVEN\MavenRepository\org\apache\tomcat\embed\tomcat-embed-el\9.0.62\tomcat-embed-el-9.0.62.jar;D:\MAVEN\MavenRepository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.62\tomcat-embed-websocket-9.0.62.jar;D:\MAVEN\MavenRepository\org\springframework\spring-web\5.3.19\spring-web-5.3.19.jar;D:\MAVEN\MavenRepository\org\springframework\spring-beans\5.3.19\spring-beans-5.3.19.jar;D:\MAVEN\MavenRepository\org\springframework\spring-webmvc\5.3.19\spring-webmvc-5.3.19.jar;D:\MAVEN\MavenRepository\org\springframework\spring-aop\5.3.19\spring-aop-5.3.19.jar;D:\MAVEN\MavenRepository\org\springframework\spring-expression\5.3.19\spring-expression-5.3.19.jar;D:\MAVEN\MavenRepository\org\apache\mahout\mahout-math\0.13.0\mahout-math-0.13.0.jar;D:\MAVEN\MavenRepository\org\apache\commons\commons-math3\3.2\commons-math3-3.2.jar;D:\MAVEN\MavenRepository\com\google\guava\guava\14.0.1\guava-14.0.1.jar;D:\MAVEN\MavenRepository\it\unimi\dsi\fastutil\7.0.12\fastutil-7.0.12.jar;D:\MAVEN\MavenRepository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;D:\MAVEN\MavenRepository\com\tdunning\t-digest\3.1\t-digest-3.1.jar;D:\MAVEN\MavenRepository\org\tribuo\tribuo-clustering-kmeans\4.3.1\tribuo-clustering-kmeans-4.3.1.jar;D:\MAVEN\MavenRepository\org\tribuo\tribuo-core\4.3.1\tribuo-core-4.3.1.jar;D:\MAVEN\MavenRepository\org\tribuo\tribuo-util-onnx\4.3.1\tribuo-util-onnx-4.3.1.jar;D:\MAVEN\MavenRepository\com\oracle\labs\olcut\olcut-config-protobuf\5.2.1\olcut-config-protobuf-5.2.1.jar;D:\MAVEN\MavenRepository\com\google\protobuf\protobuf-java\3.19.6\protobuf-java-3.19.6.jar;D:\MAVEN\MavenRepository\org\tribuo\tribuo-data\4.3.1\tribuo-data-4.3.1.jar;D:\MAVEN\MavenRepository\org\tribuo\tribuo-util-tokenization\4.3.1\tribuo-util-tokenization-4.3.1.jar;D:\MAVEN\MavenRepository\com\opencsv\opencsv\5.7.1\opencsv-5.7.1.jar;D:\MAVEN\MavenRepository\org\apache\commons\commons-text\1.10.0\commons-text-1.10.0.jar;D:\MAVEN\MavenRepository\commons-beanutils\commons-beanutils\1.9.4\commons-beanutils-1.9.4.jar;D:\MAVEN\MavenRepository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;D:\MAVEN\MavenRepository\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;D:\MAVEN\MavenRepository\org\apache\commons\commons-lang3\3.12.0\commons-lang3-3.12.0.jar;D:\MAVEN\MavenRepository\org\tribuo\tribuo-math\4.3.1\tribuo-math-4.3.1.jar;D:\MAVEN\MavenRepository\org\tribuo\tribuo-clustering-core\4.3.1\tribuo-clustering-core-4.3.1.jar;D:\MAVEN\MavenRepository\org\tribuo\tribuo-util-infotheory\4.3.1\tribuo-util-infotheory-4.3.1.jar;D:\MAVEN\MavenRepository\com\oracle\labs\olcut\olcut-core\5.2.1\olcut-core-5.2.1.jar;D:\MAVEN\MavenRepository\org\jline\jline-terminal\3.21.0\jline-terminal-3.21.0.jar;D:\MAVEN\MavenRepository\org\jline\jline-reader\3.21.0\jline-reader-3.21.0.jar;D:\MAVEN\MavenRepository\org\jline\jline-builtins\3.21.0\jline-builtins-3.21.0.jar;D:\MAVEN\MavenRepository\org\jline\jline-style\3.21.0\jline-style-3.21.0.jar;D:\MAVEN\MavenRepository\org\jline\jline-terminal-jansi\3.21.0\jline-terminal-jansi-3.21.0.jar;D:\MAVEN\MavenRepository\org\fusesource\jansi\jansi\2.4.0\jansi-2.4.0.jar;D:\MAVEN\MavenRepository\cn\xiaoandcai\JsonDiff\1.2.1\JsonDiff-1.2.1.jar;D:\MAVEN\MavenRepository\com\alibaba\fastjson2\fastjson2\2.0.7\fastjson2-2.0.7.jar;D:\MAVEN\MavenRepository\org\apache\poi\poi\5.2.3\poi-5.2.3.jar;D:\MAVEN\MavenRepository\commons-codec\commons-codec\1.15\commons-codec-1.15.jar;D:\MAVEN\MavenRepository\org\apache\commons\commons-collections4\4.4\commons-collections4-4.4.jar;D:\MAVEN\MavenRepository\commons-io\commons-io\2.11.0\commons-io-2.11.0.jar;D:\MAVEN\MavenRepository\com\zaxxer\SparseBitSet\1.2\SparseBitSet-1.2.jar;D:\MAVEN\MavenRepository\org\apache\logging\log4j\log4j-api\2.17.2\log4j-api-2.17.2.jar;D:\MAVEN\MavenRepository\org\apache\poi\poi-ooxml\5.2.3\poi-ooxml-5.2.3.jar;D:\MAVEN\MavenRepository\org\apache\poi\poi-ooxml-lite\5.2.3\poi-ooxml-lite-5.2.3.jar;D:\MAVEN\MavenRepository\org\apache\xmlbeans\xmlbeans\5.1.1\xmlbeans-5.1.1.jar;D:\MAVEN\MavenRepository\xml-apis\xml-apis\1.4.01\xml-apis-1.4.01.jar;D:\MAVEN\MavenRepository\org\apache\commons\commons-compress\1.21\commons-compress-1.21.jar;D:\MAVEN\MavenRepository\com\github\virtuald\curvesapi\1.07\curvesapi-1.07.jar;D:\MAVEN\MavenRepository\com\alibaba\easyexcel\3.3.2\easyexcel-3.3.2.jar;D:\MAVEN\MavenRepository\com\alibaba\easyexcel-core\3.3.2\easyexcel-core-3.3.2.jar;D:\MAVEN\MavenRepository\com\alibaba\easyexcel-support\3.3.2\easyexcel-support-3.3.2.jar;D:\MAVEN\MavenRepository\org\apache\poi\poi-ooxml-schemas\4.1.2\poi-ooxml-schemas-4.1.2.jar;D:\MAVEN\MavenRepository\org\apache\commons\commons-csv\1.8\commons-csv-1.8.jar;D:\MAVEN\MavenRepository\org\ehcache\ehcache\3.9.9\ehcache-3.9.9.jar;D:\MAVEN\MavenRepository\org\apache\httpcomponents\client5\httpclient5\5.2.1\httpclient5-5.2.1.jar;D:\MAVEN\MavenRepository\org\apache\httpcomponents\core5\httpcore5\5.1.3\httpcore5-5.1.3.jar;D:\MAVEN\MavenRepository\org\apache\httpcomponents\core5\httpcore5-h2\5.1.3\httpcore5-h2-5.1.3.jar;D:\MAVEN\MavenRepository\cn\hutool\hutool-http\5.8.22\hutool-http-5.8.22.jar;D:\MAVEN\MavenRepository\cn\hutool\hutool-core\5.8.22\hutool-core-5.8.22.jar;D:\MAVEN\MavenRepository\cn\hutool\hutool-all\5.8.22\hutool-all-5.8.22.jar;D:\MAVEN\MavenRepository\redis\clients\jedis\5.0.0\jedis-5.0.0.jar;D:\MAVEN\MavenRepository\org\apache\commons\commons-pool2\2.11.1\commons-pool2-2.11.1.jar;D:\MAVEN\MavenRepository\org\json\json\20230618\json-20230618.jar;D:\MAVEN\MavenRepository\com\google\code\gson\gson\2.8.9\gson-2.8.9.jar;D:\MAVEN\MavenRepository\com\alibaba\fastjson\1.2.67\fastjson-1.2.67.jar;D:\MAVEN\MavenRepository\org\projectlombok\lombok\1.18.24\lombok-1.18.24.jar;D:\MAVEN\MavenRepository\org\springframework\cloud\spring-cloud-starter-netflix-hystrix\2.2.10.RELEASE\spring-cloud-starter-netflix-hystrix-2.2.10.RELEASE.jar;D:\MAVEN\MavenRepository\org\springframework\cloud\spring-cloud-starter\2.2.9.RELEASE\spring-cloud-starter-2.2.9.RELEASE.jar;D:\MAVEN\MavenRepository\org\springframework\cloud\spring-cloud-context\2.2.9.RELEASE\spring-cloud-context-2.2.9.RELEASE.jar;D:\MAVEN\MavenRepository\org\springframework\security\spring-security-crypto\5.6.3\spring-security-crypto-5.6.3.jar;D:\MAVEN\MavenRepository\org\springframework\cloud\spring-cloud-commons\2.2.9.RELEASE\spring-cloud-commons-2.2.9.RELEASE.jar;D:\MAVEN\MavenRepository\org\springframework\security\spring-security-rsa\1.0.9.RELEASE\spring-security-rsa-1.0.9.RELEASE.jar;D:\MAVEN\MavenRepository\org\bouncycastle\bcpkix-jdk15on\1.64\bcpkix-jdk15on-1.64.jar;D:\MAVEN\MavenRepository\org\bouncycastle\bcprov-jdk15on\1.64\bcprov-jdk15on-1.64.jar;D:\MAVEN\MavenRepository\org\springframework\cloud\spring-cloud-netflix-hystrix\2.2.10.RELEASE\spring-cloud-netflix-hystrix-2.2.10.RELEASE.jar;D:\MAVEN\MavenRepository\org\springframework\boot\spring-boot-starter-aop\2.6.7\spring-boot-starter-aop-2.6.7.jar;D:\MAVEN\MavenRepository\org\springframework\cloud\spring-cloud-netflix-ribbon\2.2.10.RELEASE\spring-cloud-netflix-ribbon-2.2.10.RELEASE.jar;D:\MAVEN\MavenRepository\org\springframework\cloud\spring-cloud-netflix-archaius\2.2.10.RELEASE\spring-cloud-netflix-archaius-2.2.10.RELEASE.jar;D:\MAVEN\MavenRepository\org\springframework\cloud\spring-cloud-starter-netflix-archaius\2.2.10.RELEASE\spring-cloud-starter-netflix-archaius-2.2.10.RELEASE.jar;D:\MAVEN\MavenRepository\com\netflix\archaius\archaius-core\0.7.7\archaius-core-0.7.7.jar;D:\MAVEN\MavenRepository\com\google\code\findbugs\jsr305\3.0.1\jsr305-3.0.1.jar;D:\MAVEN\MavenRepository\commons-configuration\commons-configuration\1.8\commons-configuration-1.8.jar;D:\MAVEN\MavenRepository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\MAVEN\MavenRepository\com\netflix\hystrix\hystrix-core\1.5.18\hystrix-core-1.5.18.jar;D:\MAVEN\MavenRepository\com\netflix\hystrix\hystrix-serialization\1.5.18\hystrix-serialization-1.5.18.jar;D:\MAVEN\MavenRepository\com\fasterxml\jackson\module\jackson-module-afterburner\2.13.2\jackson-module-afterburner-2.13.2.jar;D:\MAVEN\MavenRepository\com\fasterxml\jackson\core\jackson-core\2.13.2\jackson-core-2.13.2.jar;D:\MAVEN\MavenRepository\com\fasterxml\jackson\core\jackson-annotations\2.13.2\jackson-annotations-2.13.2.jar;D:\MAVEN\MavenRepository\com\netflix\hystrix\hystrix-metrics-event-stream\1.5.18\hystrix-metrics-event-stream-1.5.18.jar;D:\MAVEN\MavenRepository\com\netflix\hystrix\hystrix-javanica\1.5.18\hystrix-javanica-1.5.18.jar;D:\MAVEN\MavenRepository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;D:\MAVEN\MavenRepository\org\aspectj\aspectjweaver\1.9.7\aspectjweaver-1.9.7.jar;D:\MAVEN\MavenRepository\io\reactivex\rxjava-reactive-streams\1.2.1\rxjava-reactive-streams-1.2.1.jar;D:\MAVEN\MavenRepository\io\reactivex\rxjava\1.3.8\rxjava-1.3.8.jar;D:\MAVEN\MavenRepository\org\reactivestreams\reactive-streams\1.0.3\reactive-streams-1.0.3.jar;D:\MAVEN\MavenRepository\org\hdrhistogram\HdrHistogram\2.1.12\HdrHistogram-2.1.12.jar;D:\idea\IntelliJ IDEA 2021.3\lib\idea_rt.jar" com.example.springbootdame.PersonalAssistantApplication
Connected to the target VM, address: '127.0.0.1:55698', transport: 'socket'
2024-01-16 15:44:01.575 [al-service] [main] WARN [org.springframework.context.annotation.AnnotationConfigApplicationContext] -Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.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 [sun.misc.Launcher$AppClassLoader@18b4aac2]
2024-01-16 15:44:01.581 [al-service] [main] INFO [org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener] -
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2024-01-16 15:44:01.603 [al-service] [main] ERROR [org.springframework.boot.SpringApplication] -Application run failed
org.springframework.beans.factory.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 [sun.misc.Launcher$AppClassLoader@18b4aac2]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213)
at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:270)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:762)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:567)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:164)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:212)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:117)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:74)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:85)
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:66)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:114)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:65)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:339)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:297)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
at com.example.springbootdame.PersonalAssistantApplication.main(PersonalAssistantApplication.java:12)
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485)
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:232)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:210)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:149)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:305)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1116)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
... 30 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467)
... 37 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 41 common frames omitted
2024-01-16 15:44:01.606 [al-service] [main] ERROR [org.springframework.boot.SpringApplication] -Application run failed
org.springframework.beans.factory.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 [sun.misc.Launcher$AppClassLoader@18b4aac2]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213)
at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:270)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:762)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:567)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:164)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:212)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:117)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:74)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:85)
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:66)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:114)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:65)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:339)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:297)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
at com.example.springbootdame.PersonalAssistantApplication.main(PersonalAssistantApplication.java:12)
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485)
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:232)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:210)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:149)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:305)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1116)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
... 30 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467)
... 37 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 41 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:55698', transport: 'socket'
Process finished with exit code 1
报错原因是缺失特定路径下的类org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata,如下所示:
需要解决此问题,自定义此类即可,注意一定要定义成框架所需的包路径(package org.springframework.boot.context.properties;):
ConfigurationBeanFactoryMetadata.java
package org.springframework.boot.context.properties;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
/**
* @Author: mingming.chen
* @Date: 2024/1/15 14 26
* @Description:
**/
public class ConfigurationBeanFactoryMetadata implements BeanFactoryPostProcessor {
private ConfigurableListableBeanFactory beanFactory;
private Map<String, MetaData> beans = new HashMap<String, MetaData>();
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
throws BeansException {
this.beanFactory = beanFactory;
for (String name : beanFactory.getBeanDefinitionNames()) {
BeanDefinition definition = beanFactory.getBeanDefinition(name);
String method = definition.getFactoryMethodName();
String bean = definition.getFactoryBeanName();
if (method != null && bean != null) {
this.beans.put(name, new MetaData(bean, method));
}
}
}
public <A extends Annotation> Map<String, Object> getBeansWithFactoryAnnotation(
Class<A> type) {
Map<String, Object> result = new HashMap<String, Object>();
for (String name : this.beans.keySet()) {
if (findFactoryAnnotation(name, type) != null) {
result.put(name, this.beanFactory.getBean(name));
}
}
return result;
}
public <A extends Annotation> A findFactoryAnnotation(String beanName,
Class<A> type) {
Method method = findFactoryMethod(beanName);
return (method == null ? null : AnnotationUtils.findAnnotation(method, type));
}
private Method findFactoryMethod(String beanName) {
if (!this.beans.containsKey(beanName)) {
return null;
}
final AtomicReference<Method> found = new AtomicReference<Method>(null);
MetaData meta = this.beans.get(beanName);
final String factory = meta.getMethod();
Class<?> type = this.beanFactory.getType(meta.getBean());
ReflectionUtils.doWithMethods(type, new ReflectionUtils.MethodCallback() {
@Override
public void doWith(Method method)
throws IllegalArgumentException, IllegalAccessException {
if (method.getName().equals(factory)) {
found.compareAndSet(null, method);
}
}
});
return found.get();
}
private static class MetaData {
private String bean;
private String method;
MetaData(String bean, String method) {
this.bean = bean;
this.method = method;
}
public String getBean() {
return this.bean;
}
public String getMethod() {
return this.method;
}
}
}
四、版本匹配安全检查问题
此时,同样启动项目,报以下错误,并中断进程:
如上所示,由于spring-cloud-starter-netflix-hystrix 2021年后不更新,此依赖包对应的springCloud版本和springboot版本不匹配,会报版本不匹配异常,需要禁用安全检查功能,如下配置在application.yml文件中:
spring:
cloud:
compatibility-verifier:
enabled: false
检查配置说明:
兼容性验证器是Spring Cloud框架中的一个功能,用于确保所使用的Spring Boot版本与Spring Cloud版本兼容。当Spring Boot版本与Spring Cloud版本不兼容时,可能会导致应用程序在运行时出现问题。
在上述代码中,cloud.compatibility-verifier.enabled
属性被设置为false
,意味着禁用了兼容性验证器。这意味着应用程序将不再执行Spring Boot与Spring Cloud版本的兼容性检查。
禁用兼容性验证器可能会导致以下问题:
- 不兼容的Spring Boot和Spring Cloud版本可能导致应用程序在运行时出现错误或异常。
- 可能会错过一些Spring Cloud提供的新功能或修复的问题。
因此,在禁用兼容性验证器之前,应该确保所使用的Spring Boot版本与Spring Cloud版本兼容,并且了解可能的风险和影响。
五、测试验证
- 熔断;
- 降级;
- 线程池隔离:并发数超过设置线程池个数请求进行降级;
六、结论
完成以上前四步即可在springboot2.6.x和2.7.x使用hystrix组件。