Annotation Interface NestedConfigurationProperty
@Target({FIELD,RECORD_COMPONENT,METHOD})
@Retention(RUNTIME)
@Documented
@Nested
public @interface NestedConfigurationProperty
Indicates that a property in a
@ConfigurationProperties
object should be treated as if it were a nested type. This annotation has no bearing on
the actual binding processes, but it is used by the
spring-boot-configuration-processor
as a hint that a property is not bound as a
single value. When this is specified, a nested group is created for the property and
its type is harvested.
In the example below, Host
is flagged as a nested property using its field and
an example.server.host
nested group is created with any property that
Host
defines:
@ConfigurationProperties("example.server")
class ServerProperties {
@NestedConfigurationProperty
private final Host host = new Host();
public Host getHost() { ... }
// Other properties, getter, setter.
}
The annotation can also be specified on a getter method. If you use records, you can annotate the record component.
This has no effect on collections and maps as these types are automatically identified.
Also, the annotation is not necessary if the target type is an inner class of the
@ConfigurationProperties
object. In the example below,
Host
is detected as a nested type as it is defined as an inner class:
@ConfigurationProperties("example.server")
class ServerProperties {
private final Host host = new Host();
public Host getHost() { ... }
// Other properties, getter, setter.
public static class Host {
// properties, getter, setter.
}
}
- Since:
- 1.2.0