Skip to content

CT Property Source

Aditya Ketkar edited this page Feb 17, 2018 · 1 revision

In Spring, you can use @PropertySource annotation to externalize your configuration to a properties file. The @PropertySource annotation is used to add any source of key-value pairs to spring’s Environment. The Environment object represents the spring environment in which the current application is running.

Example :

  1. ElasticSearchConfig.java

[The class mentioned above uses @PropertySource to autowire an Environment field, which it then passes to ElasticSearchFactoryImpl.java. This class extracts the values corresponding to specific keys from a file specified.]

Resources :

  1. http://www.baeldung.com/properties-with-spring
  2. https://www.mkyong.com/spring/spring-propertysources-example/
Clone this wiki locally