Sub topic 16
Configuration metadata and IDE support
This chapter assumes you can already bind properties with @ConfigurationProperties, as in the earlier chapters. It shows how Spring Boot describes those properties to your IDE so that application.yaml gets autocompletion, documentation popups and warnings about unknown keys.
What configuration metadata is
Configuration metadata is a JSON file named META-INF/spring-configuration-metadata.json. It lists each property key, its type, its default value and a description. IDEs such as IntelliJ IDEA (Ultimate) and Eclipse or VS Code with the Spring tooling read it from your classpath. Spring Boot's own starters ship this file for their properties, which is why server.port completes without any setup.
Your own properties get the same support only if the file is generated for them. The spring-boot-configuration-processor annotation processor does this during compilation. It scans classes annotated with @ConfigurationProperties and writes the JSON.
Adding the processor
Add it as an optional or annotation-processor dependency. It is not needed at runtime.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>In Gradle, use the annotationProcessor configuration:
dependencies {
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
}Spring Boot's dependency management supplies the version in both cases.
Documenting properties
The processor copies Javadoc into the metadata as the property description. For a record, document each component with @param.
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.DefaultValue;
/**
* Settings for outgoing mail.
*
* @param host SMTP server host name
* @param port SMTP server port
* @param retryAttempts how many times a failed send is retried
*/
@ConfigurationProperties(prefix = "app.mail")
public record MailProperties(
String host,
int port,
@DefaultValue("3") int retryAttempts) {
}After a build, target/classes/META-INF/spring-configuration-metadata.json contains entries like this one (shortened):
{
"properties": [
{
"name": "app.mail.retry-attempts",
"type": "java.lang.Integer",
"description": "How many times a failed send is retried",
"sourceType": "com.example.MailProperties",
"defaultValue": 3
}
]
}The key uses the kebab-case form, which is the canonical spelling from the relaxed binding chapter.
Adding hand-written metadata
Some keys are not bound by a class, for example ones read only with @Value. Describe them in src/main/resources/META-INF/additional-spring-configuration-metadata.json. The processor merges this file into the generated one.
{
"properties": [
{
"name": "app.feature.beta-banner",
"type": "java.lang.Boolean",
"description": "Show the beta banner on the home page.",
"defaultValue": false
}
]
}Common problems
- No completion at all. The processor is missing, or the IDE has annotation processing disabled. Enable it in the IDE settings and reimport the project.
- Stale suggestions. The JSON is regenerated only on compilation. Rebuild after you rename or add properties.
- Empty descriptions. The Javadoc is missing. On a record, put it on the type with
@param, not on the components.
Exercise
You added a new field to a @ConfigurationProperties class and documented it, but your IDE does not offer it in application.yaml. The processor dependency is already present. What should you check first?
Show answer
Rebuild the project so the processor regenerates META-INF/spring-configuration-metadata.json, and confirm the IDE has annotation processing enabled. The metadata file is only updated at compile time.