Annotation Interface ConfigurationPropertiesSource
This annotation has no effect on the actual binding process, but serves as a hint to
the spring-boot-configuration-processor to generate full metadata for the type.
Typically, this annotation is only required for types located in a different module
than the @ConfigurationProperties class that references them. When both types
are in the same module, the annotation processor can automatically discover full
metadata as long as the source is available.
Use this annotation when metadata for types located outside the module is needed:
- Nested types annotated by
@NestedConfigurationProperty - Base classes that a
@ConfigurationProperties-annotated type extends from
In the example below, ServerProperties is located in module "A" and
Host in module "B":
@ConfigurationProperties("example.server")
class ServerProperties {
@NestedConfigurationProperty
private final Host host = new Host();
public Host getHost() { ... }
// Other properties, getter, setter.
}
Properties from Host are detected as they are based on the type, but
description and default value are not. To fix this, add the
spring-boot-configuration-processor to module "B" if it is not present already
and update Host as follows::
@ConfigurationPropertiesSource
class Host {
/**
* URL to use.
*/
private String url = "https://example.com";
// Other properties, getter, setter.
}
Similarly the metadata of a base class that a
@ConfigurationProperties-annotated type extends from can also be detected.
Consider the following example:
@ConfigurationProperties("example.client.github")
class GitHubClientProperties extends AbstractClientProperties {
// Additional properties, getter, setter.
}
As with nested types, adding @ConfigurationPropertiesSource to
AbstractClientProperties and the spring-boot-configuration-processor to
its module ensures full metadata generation.
- Since:
- 4.0.0
- Author:
- Stephane Nicoll