As of Spring Boot 2.2, we can use the @ConstructorBinding
annotation to bind our configuration properties.
This essentially means that @ConfigurationProperties-annotated classes may now be immutable.
The @ConstructorBinding
annotation indicates that configuration properties should be bound via constructor arguments rather than by calling setters
It's important to emphasize that to use the constructor binding, we need to explicitly enable our configuration class either with @EnableConfigurationProperties
or with @ConfigurationPropertiesScan
If you don't have config class you can add it above the main application class:
@SpringBootApplication
@EnableConfigurationProperties(MyAwesome::class)