gpt4 book ai didi

spring-boot - 升级到 Spring Boot 2.4.0 打破传统应用

转载 作者:行者123 更新时间:2023-12-03 14:46:40 28 4
gpt4 key购买 nike

我正在将一组遗留应用程序升级到 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
为了 Kubernetes,他们从 Spring Boot 中删除了一个基本类。我不确定我明白为什么。
我做了谷歌搜索,发现 this解释和修复。
我加了 spring.config.use-legacy-processing到我的 application.yml和一个测试 application.properties文件:
spring:
config:
use-legacy-processing: true
仍然没有快乐 - 所有的测试都失败了。
我被 other links 弄糊涂了我见过。这是 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>
问题比测试更大。如果我忽略它们并尝试运行该应用程序,我仍然会失败:
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]
根本原因是一样的:
java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata

最佳答案

每当您在 Spring 进行升级时,请务必查看 spring / cloud compatibility matrix然后相应地升级 spring 和 cloud 的版本:
另外,请注意,您可能没有将 spring cloud 添加为直接依赖项,但它可能会作为传递依赖项进入您的最终 jar,因此最好在您的 pom 中添加 spring cloud 依赖项作为直接依赖项管理,以远离任何冲突:

<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>

关于spring-boot - 升级到 Spring Boot 2.4.0 打破传统应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65224327/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com