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)
  • @TestPropertySource annotations on tests
  • Properties attribute in @SpringBootTest tests
  • Command-line arguments
  • Properties from SPRINGAPPLICATIONJSON property
  • ServletConfig init parameters
  • ServletContext init parameters
  • JNDI attributes from java:comp/env
  • JVM system properties
  • System Environment Variables
  • RandomValuePropertySource - ${random.*}
  • application-{profile}.properties and YAML variants - outside of jar
  • application-{profile}.properties and YAML variants – inside jar
  • application.properties and YAML variants - outside of jar
  • application.properties and YAML variants - inside jar
  • @PropertySource annotations on @Configuration classes
  • Default properties - SpringApplication.setDefaultProperties