Spring
May 29, 2020
M01 Q12 What is a property source? How to use @PropertySource?
PropertySource is Spring Abstraction on Environment Key-Value pairs, which can come from:
- JVM Properties
- System Environmental Variables
- JNDI Properties
- Servlet Parameters
- Properties File Located on Filesystem
- Properties File Located on Classpath
It is a good way to access all of the properties with the usage of the same mechanism without having to distinguish whether this property is coming from JVM or from the system.
Remember that, JVM Properties, System Environmental Variables, JNDI Properties, Servlet Parameters are already read for you.
You read properties with the usage of @PropertySource or @PropertySources annotation:
You access properties with the usage of @Value annotation: