Sub topic 16
Configuration metadata and IDE support
This chapter assumes you can write @ConfigurationProperties classes (see "Binding groups of properties with @ConfigurationProperties") and that you build with Maven or Gradle. By the end you will know how Spring Boot produces configuration metadata, what the metadata contains, and how to extend it so your editor completes and checks your own properties.
What configuration metadata is
Spring Boot's own properties, such as server.port, get autocompletion and documentation popups in good editors. Your own properties can get the same support through configuration metadata. This is a JSON file, META-INF/spring-configuration-metadata.json, that describes each property: its name, type, default value, description, and deprecation status.
Metadata is for tools only. The binder does not read it at runtime. An application with no metadata binds and validates properties exactly as before. The value is in the editor:
- Completion for keys such as
app.mail.retry-attemptswhile you type inapplication.yaml. - Documentation popups taken from your Javadoc.
- Warnings for keys that match no known property.
- Strikethrough for deprecated keys, with a pointer to the replacement.
The warning for unknown keys matters because Spring Boot ignores unknown keys by default. If you write app.mail.retry-atempts: 5, the application starts normally and silently uses the default of 3. An IDE that knows the metadata flags the typo as you write it.
Generating metadata with the annotation processor
The spring-boot-configuration-processor is a Java annotation processor. During compilation it scans your @ConfigurationProperties classes and writes the metadata file into the build output.
Add it to Maven like this. The Spring Boot parent or BOM supplies the version.
<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'
}The processor is needed only at compile time. <optional>true</optional> in Maven keeps it from reaching projects that depend on yours. If your Maven build lists annotationProcessorPaths in the compiler plugin, add the processor there instead.
Describing properties with Javadoc
The processor takes each property's description from Javadoc. For a record, put @param tags in the record's Javadoc, one per component. Here is the MailProperties record from earlier in the tutorial, documented:
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.validation.annotation.Validated;
/**
* Settings for outgoing mail.
*
* @param host SMTP server host name.
* @param port SMTP server port, between 1 and 65535.
* @param sender Address used in the From header.
* @param retryAttempts Number of times a failed send is retried.
*/
@Validated
@ConfigurationProperties(prefix = "app.mail")
public record MailProperties(
@NotBlank String host,
@Min(1) @Max(65535) int port,
@Email String sender,
@DefaultValue("3") int retryAttempts) {
}After a build, the generated file contains an entry for the group and for each property. An abridged version looks like this:
{
"groups": [
{
"name": "app.mail",
"type": "com.example.MailProperties",
"sourceType": "com.example.MailProperties"
}
],
"properties": [
{
"name": "app.mail.host",
"type": "java.lang.String",
"description": "SMTP server host name.",
"sourceType": "com.example.MailProperties"
},
{
"name": "app.mail.retry-attempts",
"type": "java.lang.Integer",
"description": "Number of times a failed send is retried.",
"sourceType": "com.example.MailProperties",
"defaultValue": 3
}
],
"hints": []
}Some details to note:
- Property names appear in kebab-case (
retry-attempts), the canonical form from the relaxed binding chapter. That is the spelling the IDE inserts. - The processor only reads the Javadoc. It does not run your code, so it cannot evaluate defaults that are computed at runtime.
- Keep descriptions short. Boot's guidance is to start with a brief sentence that ends in a period, because tools show the first sentence in the popup. Do not start with "The" or "A".
- Constructor-bound and JavaBean-style classes are both supported.
Adding manual metadata
The processor sees only @ConfigurationProperties types and @Bean methods that carry the annotation. It does not see a key read with @Value or Environment.getProperty. For these keys, and for hints about valid values, write src/main/resources/META-INF/additional-spring-configuration-metadata.json. At compile time the processor merges it into the generated file.
{
"properties": [
{
"name": "app.banner.enabled",
"type": "java.lang.Boolean",
"description": "Whether the startup banner message is printed.",
"defaultValue": true
},
{
"name": "app.mail.retries",
"type": "java.lang.Integer",
"description": "Old name of the retry count.",
"deprecation": {
"reason": "Renamed for consistency.",
"replacement": "app.mail.retry-attempts"
}
}
],
"hints": [
{
"name": "app.mail.host",
"values": [
{ "value": "localhost", "description": "Local test SMTP server." },
{ "value": "smtp.example.com", "description": "Production relay." }
]
}
]
}This file does three jobs:
- Documents keys the processor cannot find.
app.banner.enablednow completes and is no longer flagged as unknown. - Marks a property deprecated. The editor strikes out
app.mail.retriesand offersapp.mail.retry-attempts. Thereasonandreplacementfields drive the message. For JavaBean-style classes you can instead annotate the getter with@DeprecatedConfigurationProperty. The JSON route works for every class shape and for keys that no longer exist in any class. - Offers value hints. The editor suggests the listed values when you complete
app.mail.host. Hints are suggestions, and any other value is still accepted.
What the IDE needs
Editors differ in which part of their setup matters:
- IntelliJ IDEA Ultimate reads the metadata from the classpath. Enable annotation processing (Settings, Build, Compiler, Annotation Processors) so the metadata is regenerated when you change a properties class.
- Spring Tools for Eclipse and VS Code read the metadata of the dependencies and of your own project once it has been built.
- Editors without Spring support can still show YAML or
.propertiessyntax, but they have no key completion.
The metadata is regenerated at compile time. If you add a field and the new key does not complete, rebuild the project first, and only then suspect the IDE. Also check target/classes/META-INF/spring-configuration-metadata.json for Maven, or build/classes/java/main/META-INF/ for Gradle. If the key is in that file, the problem is in the IDE.
Common problems
| Symptom | Likely cause | Fix |
|---|---|---|
| No metadata file is generated | Processor missing from the compiler's processor path | Add the dependency or `annotationProcessor` entry, then do a clean build |
| Key completes but has no description | Missing Javadoc, or `@param` absent on a record | Document each record component with `@param` |
| `@Value` key flagged as unknown | The processor does not scan `@Value` | Add it to `additional-spring-configuration-metadata.json` |
| Stale entries after a rename | Old build output is still present | Run a clean build |
| Editor shows a warning, but the app runs | Metadata is advisory | Fix the key or the metadata, since startup is unaffected |
Exercise
You add a new field timeout to a properties record and write app.mail.timeout: 10 in application.yaml. The IDE flags the key as unknown, but the application starts and binds the value. What explains this, and what do you check first?
Show answer
The metadata is used only by tools, never by the binder, so a stale or missing metadata file makes the IDE warn while binding works normally. Rebuild the project so the annotation processor regenerates the file, then check that META-INF/spring-configuration-metadata.json in the build output contains app.mail.timeout. If the file is not generated at all, confirm that spring-boot-configuration-processor is on the compiler's annotation processor path.
Exercise
Your service reads app.banner.enabled with @Value("${app.banner.enabled:true}"). How do you make this key complete in the IDE with a description?
Show answer
Create src/main/resources/META-INF/additional-spring-configuration-metadata.json with a properties entry named app.banner.enabled, type java.lang.Boolean, a description, and defaultValue true. The processor does not scan @Value, so the key must be declared by hand. The processor merges the file into the generated metadata on the next build.