我有一个 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
有谁知道可能导致此问题的原因和/或我可能需要采取哪些措施来解决它?
对于 Spring Boot,每个次要版本更新都可能引入重大更改。通常有一两个版本的类等在被删除之前就被弃用了。由于您实际上是在升级 3 个次要版本,因此您错过了如果分别从 2.3 升级到 2.4、2.5 到 2.6 时可能会收到的一些弃用警告。
查看 Spring Boot 版本说明2.4 https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.4-Release-Notes, 2.5 https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.5-Release-Notes and 2.6 https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.6-Release-Notes自 2.3 以来所做的更改。重大变化都应该被提及。
在这种情况下,我发现了以下条目:
SpringPhysicalNamingStrategy 已被弃用,取而代之的是 Hibernate 5.5 的 CamelCaseToUnderscoresNamingStrategy
由于只有单元测试失败,因此您可能定义了较旧的 Hibernate 版本。删除它并使用 Spring Boot 提供的一个。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)