springboot
upgrade
ClassNotFoundException
ConfigurationBeanFactoryMetadata
troubleshooting

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.

Browse interview questions

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:

 
1java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
2    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
3    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
4    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
5    ...

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

  1. 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.
  2. Use Alternative Approaches:
    • Spring Boot 2.4.x offers a new way of handling configuration metadata and properties.
    • Explore using @ConfigurationProperties and the newer Property Source abstraction.
  3. 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.
  4. 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:

java
1import org.springframework.boot.context.properties.ConfigurationProperties;
2import org.springframework.stereotype.Component;
3
4@Component
5@ConfigurationProperties(prefix = "example.config")
6public class ExampleConfig {
7    private String propertyOne;
8    private int propertyTwo;
9
10    // Getters and Setters
11    public String getPropertyOne() {
12        return propertyOne;
13    }
14
15    public void setPropertyOne(String propertyOne) {
16        this.propertyOne = propertyOne;
17    }
18
19    public int getPropertyTwo() {
20        return propertyTwo;
21    }
22
23    public void setPropertyTwo(int propertyTwo) {
24        this.propertyTwo = propertyTwo;
25    }
26}

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 & ActionDescription
Class Removedorg.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
ManifestationClassNotFoundException when class is referenced
First StepAudit your dependencies and custom code to find usage of this class
Preferred PracticeUse @ConfigurationProperties to bind configuration properties
Dependency ConsiderationsUpgrade or exclude dependencies using now-removed classes
Release NotesAlways 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
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Browse interview questions

All Rights Reserved.