Spring Boot
September 9, 2021
M04 Q10 How do you access the properties defined in the property files?
Spring Boot allows you to access properties defined in property files in following ways:
@Value("${PROPERTY_NAME}")You can inject properties into fields with usage of @Value annotation:
@ConfigurationProperties
Also, you you need to have setters for Spring to set properties to this class.
You can define Data Object which will hold properties for defined prefix, you also need to register Configuration Properties Data Object with usage of EnableConfigurationProperties:
Inject and use Environment object.