springboot Upgrade from 2.3.5.RELEASE to 2.4.1- ClassNotFoundException org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Upgrading from Spring Boot 2.3.5.RELEASE to 2.4.1 can occasionally encounter some backward compatibility issues, one of which is the ClassNotFoundException for org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata. This article explains this issue, provides potential solutions, and delves into associated technical details.
Understanding the Issue
In Spring Boot 2.3.x, ConfigurationBeanFactoryMetadata was part of the internals used for binding configuration properties. However, with Spring Boot 2.4.x, there were significant changes including the introduction of a new configuration property binding system. Due to these changes, the ConfigurationBeanFactoryMetadata class was removed, leading to ClassNotFoundException when references to this class are made.
The error might look like the following in your logs:
Why This Exception Occurs
The ClassNotFoundException generally occurs if a piece of code attempts to use a class that is not present on the classpath. In this case, if any third-party libraries, custom code, or configuration is using ConfigurationBeanFactoryMetadata, it will result in this exception after upgrading to Spring Boot 2.4.1.
Solutions to Resolve the Issue
- Check Dependencies and Custom Code:
- Audit your dependencies and custom code base for usage of
ConfigurationBeanFactoryMetadata. - If found in third-party libraries, check with the library maintainers for updates that support Spring Boot 2.4.x.
- Use Alternative Approaches:
- Spring Boot 2.4.x offers a new way of handling configuration metadata and properties.
- Explore using
@ConfigurationPropertiesand the newer Property Source abstraction.
- Exclude or Upgrade Conflicting Libraries:
- Exclude conflicting libraries that rely on older versions of Spring Boot internally.
- Gradually upgrade the versions of dependencies to those compatible with Spring Boot 2.4.1 or higher.
- Spring Boot Upgrade Notes:
- Review Spring Boot's release notes and migration guides for custom parts of the applications. These can often contain important notes on deprecations and removals.
Example of Handling Configuration
Assuming there is an old class using ConfigurationBeanFactoryMetadata, you should update the configuration binding to comply with the new system. An example of defining properties can be written as follows:
This code showcases a way to use @ConfigurationProperties to bind properties from configuration files.
Summary Table
Below is a summary table highlighting key aspects of the upgrade process and resolution strategies.
| Feature & Action | Description |
| Class Removed | org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata |
| Manifestation | ClassNotFoundException when class is referenced |
| First Step | Audit your dependencies and custom code to find usage of this class |
| Preferred Practice | Use @ConfigurationProperties to bind configuration properties |
| Dependency Considerations | Upgrade or exclude dependencies using now-removed classes |
| Release Notes | Always refer to Spring Boot Migration Guides |
Additional Considerations
- Configuration Hierarchy: In (2.4.x), property source ordering has seen improvements, and understanding the default order can help avoid surprises.
- Profile-Specific Properties: Spring Boot (2.4.x) introduced profile-specific properties with a more flexible syntax allowing profiles to be hierarchical, enabling complex configurations more gracefully.
- Backward Compatibility Caution: If your applications leverage APIs or internals that have been heavily deprecated in earlier Spring Boot versions, consider more comprehensive testing to ensure seamless migration.
This detail-oriented approach to handling the Spring Boot upgrade can save time debugging issues such as the ClassNotFoundException. Always ensure to leverage official documentation and community support forums which are invaluable resources during such transitions.
Related reading
- Springfox 3.0.0 is not working with Spring Boot 2.6.0
- Springfox Type javax.servlet.http.HttpServletRequest not present
- Spyder internal error while trying to open array
- SQL connection throws error when adding DistributedSession, SessionMiddleware
- SQL Replication Error On Server Agent
- SQL Server 2014 - Missing option on Replication
- Sql Server 'Saving changes is not permitted' error ► Prevent saving changes that require table re-creation
- SQL UPDATE all values in a field with appended string CONCAT not working
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.