The Spring Boot documentation says that to use the @ConfigurationProperties
annotation
You also need to list the properties classes to register in the
@EnableConfigurationProperties
annotation, as shown in the following example:
and gives this code:
@Configuration
@EnableConfigurationProperties(AcmeProperties.class)
public class MyConfiguration {
}
But in the very next paragraph says:
Even if the preceding configuration creates a regular bean for AcmeProperties, we recommend that
@ConfigurationProperties
only deal with the environment and, in particular, does not inject other beans from the context. Having said that, the@EnableConfigurationProperties
annotation is also automatically applied to your project so that any existing bean annotated with@ConfigurationProperties
is configured from theEnvironment
.
Suggesting that listing a @ConfigurationProperties
bean under an @EnableConfigurationProperties
annotation is not necessary.
So which is it? Experimentally, I've seen that if I annotate a bean with @ConfigurationProperties
it gets properties injected to it as expected without needing to list it in @EnableConfigurationProperties
, but if this is the case then why list anything that has a @ConfigurationProperties
annotation under @EnableConfigurationProperties
, as is shown in the documentation? Does it make any kind of difference?