将 spring-boot-starter-parent 升级到版本 2.6.6 后,Java Spring Boot java.lang.NoClassDefFoundError

dgc*_*dgc 4 java spring-boot

我有一个 Spring Boot 应用程序,一直在使用 spring-boot-starter-parent 版本 2.3.9.RELEASE。由于存在漏洞,我们需要更新应用程序以使用版本 2.6.6。

升级后,我的一些单元测试出现错误:

testGetDiscount(com.ally.abmt.integrationapi.util.IntegrationApiUtilTest)  Time elapsed: 0 sec  <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/boot/model/naming/CamelCaseToUnderscoresNamingStrategy
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/boot/model/naming/CamelCaseToUnderscoresNamingStrategy
Caused by: java.lang.NoClassDefFoundError: org/hibernate/boot/model/naming/CamelCaseToUnderscoresNamingStrategy
Run Code Online (Sandbox Code Playgroud)

有谁知道可能导致此问题的原因和/或我可能需要采取哪些措施来解决它?

Rob*_*oor 10

对于 Spring Boot,每个次要版本更新都可能引入重大更改。通常有一两个版本的类等在被删除之前就被弃用了。由于您实际上正在升级 3 个次要版本,因此您错过了如果分别从 2.3 升级到 2.4、2.5 到 2.6 时可能会收到的一些弃用警告。

\n

查看 Spring Boot 版本2.42.52.6的发行说明,了解自 2.3 以来所做的更改。重大变化都应该被提及。

\n

在这种情况下,我发现了以下条目:

\n
\n

SpringPhysicalNamingStrategy 已被弃用,取而代之的是 Hibernate 5.5\xe2\x80\x99s CamelCaseToUnderscoresNamingStrategy

\n
\n

由于只有单元测试失败,因此您可能定义了较旧的 Hibernate 版本。删除它并使用 Spring Boot 提供的一个。

\n