duf*_*ymo 7 intellij-idea spring-boot spring-cloud junit5
我正在将一组遗留应用程序升级到 Spring Boot 2.4.0,在 OpenJDK 8 上运行,部署到 Pivotal Cloud Foundry。
在我开始升级之前,该应用程序及其所有单元测试在 Spring 2.3.4-RELEASE 下完美运行。
有一些工作需要立即完成:Spring Boot 2.4.0 引入了 JUnit 5.x,所以我必须修复所有 JUnit 4.x 测试以使用新的注释和类。
修复所有测试后,我尝试在 IntelliJ 2020.2 中运行。由于相同的原因,所有测试都失败了:java.lang.IllegalStateException: Failed to load ApplicationContext
. 堆栈跟踪的根源给出了这个原因:
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
Run Code Online (Sandbox Code Playgroud)
为了 Kubernetes,他们从 Spring Boot 中删除了一个基本类。我不确定我明白为什么。
我做了谷歌搜索,找到了这个解释和修复。
我添加spring.config.use-legacy-processing
到我的application.yml
和一个测试application.properties
文件中:
spring:
config:
use-legacy-processing: true
Run Code Online (Sandbox Code Playgroud)
仍然没有快乐 - 所有的测试都失败了。
我对我看到的其他链接感到困惑。这是一个问题spring-cloud-dependencies
吗?我读到Hoxton
版本可能有问题。我需要将它添加到我的应用程序中吗?在升级之前它从不需要这个依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR9</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
问题比测试更大。如果我忽略它们并尝试运行该应用程序,我仍然会失败:
ERROR [main]: Application run failed |ApplicationName=Risk_Advisor | sourcedfrom=ERROR
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]
Run Code Online (Sandbox Code Playgroud)
根本原因是一样的:
java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
Run Code Online (Sandbox Code Playgroud)
我在迁移到Spring Boot 2.4.4时遇到了同样的错误,这迫使我也迁移到Spring Cloud 2020.0.1 。就我而言,错误是由于由 提供的Bootstrapspring-cloud-commons
造成的,默认情况下不再启用。build.gradle
我必须通过在我的文件中添加以下新启动器来重新启用它,如下所示:
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'
Run Code Online (Sandbox Code Playgroud)
你说你的应用程序不使用Spring Cloud,所以我不确定为什么你最终会面临同样的问题。希望这个解决方法对您有用,并帮助其他使用 Spring Cloud 的人。
为了修复失败的 JUnit 4 测试,我刚刚将其添加为依赖项:
testImplementation 'junit:junit:4.13'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5538 次 |
最近记录: |