Posts

Showing posts with the label @PropertySource

Spring @PropertySource Annotation Example

Image
In this section we will learn about @PropertySource  Annotation. The  @PropertySource  is a convenient annotation for including PropertySource to Spring's Environment and allowing to inject properties via @Value into class attributes.  This annotation is used with @Configuration classes. Spring @PropertySource annotation is repeatable, means you can have multiple @PropertySource on a Configuration class. This feature is available if you are using Java 8 or higher version.  For earlier java versions, @PropertySources was the way to provide multiple property files to the configuration class. The following example creates a Spring Boot web application which uses  @PropertySource annotation . Project Directory db.properties DB_DRIVER_CLASS = com.mysql.jdbc.Driver DB_URL = jdbc:mysql://localhost:3306/Demo DB_USERNAME = knf DB_PASSWORD = root message.properties hello.message = Hello World knowledgefactory.properties knf.message = Hi, Greetings from knowledgefactory.net. language.lis