Spring
June 7, 2020
M01 Q32 Where can properties in the environment come from?
Property Sources in Spring Application vary based on the type of applications that is being executed:
- Standalone Application
- Servlet Container Application
- Spring Boot Application
Property Sources for Standalone Spring Framework Application:
- Properties Files
- JVM system properties
- System Environment Variables
Property Sources for Servlet Container Spring Framework Application:
- Properties Files
- JVM system properties
- System Environment Variables
- JNDI
- ServletConfig init parameters
- ServletContext init parameters
Property Sources for Spring Boot Application:
- Devtools properties from
~/.spring-boot-devtools.properties(when devtools is active) @TestPropertySourceannotations on tests- Properties attribute in
@SpringBootTesttests - Command-line arguments
- Properties from SPRINGAPPLICATIONJSON property
ServletConfiginit parametersServletContextinit parameters- JNDI attributes from
java:comp/env - JVM system properties
- System Environment Variables
- RandomValuePropertySource -
${random.*} application-{profile}.propertiesand YAML variants - outside of jarapplication-{profile}.propertiesand YAML variants – inside jarapplication.propertiesand YAML variants - outside of jarapplication.propertiesand YAML variants - inside jar@PropertySourceannotations on@Configurationclasses- Default properties -
SpringApplication.setDefaultProperties