Spring Boot allows you to create your own customized configuration of application properties with beans. You can register these beans as properties with Spring Boot by using the @ConfigurationProperties annotation, and after this, you can set these properties by using either the application.properties or application.yml file.
Spring Boot provides alternative ways of working with properties that allow you to strongly type safe beans and validate the configuration of your application. Let's see the use of the @ConfigurationProperties annotation for a dedicated container bean:
- This @ConfigurationProperties annotation will hold the externalized properties
- It avoids repeating the prefix
- Data members automatically set from corresponding properties
Let's see the following example:
@Component @ConfigurationProperties(prefix=...