Add ability to ignore configuration properties

Properties which should be ignored can be specified in the
additional-spring-configuration-metadata.json file. The ignored
properties section is copied into the final
spring-configuration-metadata.json file, and the ignored properties are
removed from the properties element in the final file.

Closes gh-2421
This commit is contained in:
Moritz Halbritter
2025-01-21 15:21:44 +01:00
parent 08e9c16f33
commit f24ba9935c
11 changed files with 375 additions and 16 deletions

View File

@@ -160,12 +160,14 @@ TIP: This has no effect on collections and maps, as those types are automaticall
== Adding Additional Metadata
Spring Boot's configuration file handling is quite flexible, and it is often the case that properties may exist that are not bound to a javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] bean.
You may also need to tune some attributes of an existing key.
You may also need to tune some attributes of an existing key or to ignore the key altogether.
To support such cases and let you provide custom "hints", the annotation processor automatically merges items from `META-INF/additional-spring-configuration-metadata.json` into the main metadata file.
If you refer to a property that has been detected automatically, the description, default value, and deprecation information are overridden, if specified.
If the manual property declaration is not identified in the current module, it is added as a new property.
The format of the `additional-spring-configuration-metadata.json` file is exactly the same as the regular `spring-configuration-metadata.json`.
The items contained in the "`ignored.properties`" section are removed from the "`properties`" section of the generated `spring-configuration-metadata.json` file.
The additional properties file is optional.
If you do not have any additional properties, do not add the file.

View File

@@ -2,7 +2,7 @@
= Metadata Format
Configuration metadata files are located inside jars under `META-INF/spring-configuration-metadata.json`.
They use a JSON format with items categorized under either "`groups`" or "`properties`" and additional values hints categorized under "hints", as shown in the following example:
They use a JSON format with items categorized under either "`groups`" or "`properties`", additional values hints categorized under "hints", and ignored items under "`ignored`" as shown in the following example:
[source,json]
----
@@ -63,7 +63,15 @@ They use a JSON format with items categorized under either "`groups`" or "`prope
}
]
}
]}
...
],"ignored": {
"properties": [
{
"name": "server.ignored"
}
...
]
}}
----
Each "`property`" is a configuration item that the user specifies with a given value.
@@ -82,9 +90,12 @@ For example, the `server.port` and `server.address` properties are part of the `
NOTE: It is not required that every "`property`" has a "`group`".
Some properties might exist in their own right.
Finally, "`hints`" are additional information used to assist the user in configuring a given property.
The "`hints`" are additional information used to assist the user in configuring a given property.
For example, when a developer is configuring the configprop:spring.jpa.hibernate.ddl-auto[] property, a tool can use the hints to offer some auto-completion help for the `none`, `validate`, `update`, `create`, and `create-drop` values.
Finally, "`ignored`" are items which have been deliberately ignored.
The content of this section usually comes from the xref:specification:configuration-metadata/annotation-processor.adoc#appendix.configuration-metadata.annotation-processor.adding-additional-metadata[additional metadata].
[[appendix.configuration-metadata.format.group]]
@@ -292,6 +303,36 @@ The JSON object contained in the `providers` attribute of each `hint` element ca
[[appendix.configuration-metadata.format.ignored]]
== Ignored Attributes
The `ignored` object can contain the attributes shown in the following table:
[cols="1,1,4"]
|===
| Name | Type | Purpose
| `properties`
| IgnoredProperty[]
| A list of ignored properties as defined by the IgnoredProperty object (described in the next table). Each entry defines the name of the ignored property.
|===
The JSON object contained in the `properties` attribute of each `ignored` element can contain the attributes described in the following table:
[cols="1,1,4"]
|===
| Name | Type | Purpose
| `name`
| String
| The full name of the property to ignore.
Names are in lower-case period-separated form (such as `spring.mvc.servlet.path`).
This attribute is mandatory.
|===
[[appendix.configuration-metadata.format.repeated-items]]
== Repeated Metadata Items