How to Auto-Generate spring-configuration-metadata.json for Spring Boot Starters
This article explains the role of the spring.factories file in Spring Boot starters, shows its typical content, and demonstrates how to automatically generate the spring-configuration-metadata.json file by adding the configuration processor dependency and properly annotating configuration property classes.
In a previous post I discussed that the spring.factories file in a Spring Boot starter is no longer recommended, and a reader asked where this file is located.
The file resides under the /META-INF/ directory.
Its typical content looks like this:
{
"groups": [
{
"name": "swagger",
"type": "com.spring4all.swagger.SwaggerProperties",
"sourceType": "com.spring4all.swagger.SwaggerProperties"
},
{
"name": "swagger.authorization",
"type": "com.spring4all.swagger.SwaggerAuthorizationProperties",
"sourceType": "com.spring4all.swagger.SwaggerAuthorizationProperties"
},
{
"name": "swagger.contact",
"type": "com.spring4all.swagger.SwaggerProperties$Contact",
"sourceType": "com.spring4all.swagger.SwaggerProperties"
}
// ... more entries ...
]
}The purpose of spring.factories is to tell Spring Boot which configuration classes to load for the starter, and the file provides configuration metadata that IDEs can use to offer code completion and documentation hints.
When the metadata is present, developers get helpful suggestions while writing configuration properties, making the starter easier to use.
How to Auto-Generate?
You can also automatically generate the spring-configuration-metadata.json file by adding the Spring Boot configuration processor to your pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>After adding this dependency, recompiling the project creates the spring-configuration-metadata.json file automatically, provided that your configuration property classes are properly annotated and documented.
Example of a configuration properties class with Lombok, Spring Boot annotations, and Javadoc comments:
@Data
@ConfigurationProperties("swagger")
public class SwaggerProperties {
/**
* Title
*/
private String title = "";
/**
* Description
*/
private String description = "";
// ... other fields ...
}With the processor in place, the IDE will display the comments from the fields as part of the auto‑completion suggestions for the corresponding configuration keys.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
