Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Spring Boot java.lang.NoClassDefFoundError after upgrading spring-boot-starter-parent to version 2.6.6 [closed]

I have a Spring Boot application that has been using spring-boot-starter-parent version 2.3.9.RELEASE. Due to vulnerabilities, we are required to update the application to use version 2.6.6.

After upgrade, a bunch of my unit tests error out with:

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

Does anyone have any ideas about what might be causing this and/or what I might need to do to resolve it?

like image 339
dgc Avatar asked Sep 16 '25 14:09

dgc


1 Answers

For Spring Boot, every minor version bump can introduce breaking changes. Usually there are one or two versions where classes etc. are deprecated before they are removed. Since you're effectively upgrading 3 minor versions, you missed some of the deprecation warnings you would have gotten if you upgraded from 2.3 to 2.4 to 2.5 to 2.6 separately.

Check out the Spring Boot release notes for version 2.4, 2.5 and 2.6 for the changes made since 2.3. The breaking changes should all be mentioned.

In this case, I found the following entry:

SpringPhysicalNamingStrategy has been deprecated in favor of Hibernate 5.5’s CamelCaseToUnderscoresNamingStrategy

Since only your unit tests fail, you may have an older Hibernate version defined. Remove it and use the one Spring Boot provides.

like image 63
Rob Spoor Avatar answered Sep 19 '25 06:09

Rob Spoor