@Documented @Retention(value=RUNTIME) @Target(value={METHOD,TYPE}) @Singleton @ConfigurationReader public @interface EachProperty
This annotation allows driving the production of Bean
definitions from either configuration or the
presence of another bean definition
For example:
@EachProperty("foo.bar")
public class ExampleConfiguration {
}
In the above example a new ExampleConfiguration
bean will be created for each item under the
foo.bar
key in application configuration
A reference to the configuration entry name can be obtained with the Parameter
annotation applied to a
constructor argument:
@EachProperty("foo.bar")
public class ExampleConfiguration {
ExampleConfiguration( @Parameter String name) {
...
}
}
In the above example for a configuration property of foo.bar.test
, the value of the name
argument
will be "test"
The bean is created as a singleton with a Named
qualifier matching the configuration entry
name, thus allowing retrieval with:
ExampleConfiguration exampleConfiguration = applicationContext.getBean(ExampleConfiguration.class, Qualifiers.byName("test"));
Or alternatively dependency injection via the Named
qualifier.
This annotation is typically used in conjunction with EachBean
. For example, one can drive the
configuration of other beans with the EachBean
annotation:
@EachBean(ExampleConfiguration)
@Singleton
public class ExampleBean {
ExampleBean(ExampleConfiguration config) {
...
}
}
EachBean
,
ConfigurationProperties
Modifier and Type | Required Element and Description |
---|---|
java.lang.String |
value
Defines the property this
EachProperty is driven by. |
@AliasFor(annotation=ConfigurationReader.class, member="value") public abstract java.lang.String value
EachProperty
is driven by. Should be in kebab case form. Example: "my-app.bar".@AliasFor(annotation=ConfigurationReader.class, member="includes") public abstract java.lang.String[] includes
@AliasFor(annotation=ConfigurationReader.class, member="excludes") public abstract java.lang.String[] excludes
public abstract boolean list
EachProperty
binds to a map where
the key is a string and the value is an instance of the annotated class.