in Spring boot

Spring boot Configuration properties

Spring boot is awesome and it allows you to configure your app using external properties file (application.properties) with no problem at all. Here is the example of the application.property file located in the class path.

Injecting myValue is super easy, it can be done using @Value annotation like this

Same would go for other awesomeConfiguration values and here is the problem. We have a number of items that all belong to the group awesomeConfiguration it would be great if we could load all the values into the spring bean. Configuration properties to the rescue!

ConfigurationProperties

Configuration properties is set using 3 steps

1: Create POJO object where all property values are going to be loaded and specify @ConfigurationProperties with prefix to control what values are used.

2: enable Configuration properties in your spring config class using annotation @EnableConfigurationProperties

3: Inject AwesomeConfiguration

Done.

 

Write a Comment

Comment