You shouldn’t mix @Value
and @ConfigurationProperties
in the same class. If you want to have default values in a @ConfigurationProperties
-annotated class, you can configure the fields with a default value:
@ConfigurationProperties("foo")
public class FooConfig {
private Integer iterations = 999;
// getter / setter
}
This change brings with it the added benefit of including the default value in the metadata that’s generated by spring-boot-configuration-processor
. The metadata is used by your IDE to provide auto-completion when you’re editing application.properties
and application.yaml
files.
Lastly, and not directly related to your problem, a @ConfigurationProperties
-annotated class should not be annotated with @Configuration
. An @Configuration
-annotated class is used to configure beans via @Bean
methods. Your FooConfig
class should either be annotated with @Component
or you should use @EnableConfigurationProperties(FooConfig.class)
on the @Configuration
class that wants to use FooConfig
.