Springboot configuration loading order

Transfer: https://blog.csdn.net/zl1zl2zl3/article/details/83716564

1, Devtools global settings properties on your home directory (~/.spring -boot-devtools.properties when devtools is active).
2, @TestPropertySource annotations on your tests.
3, @SpringBootTest#properties annotation attribute on your tests.
4, Command line arguments.
5, Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property)
6, ServletConfig init parameters.
7, ServletContext init parameters.
8, JNDI attributes from java:comp/env.
9、Java System properties (System.getProperties()).
10、OS environment variables.
11、A RandomValuePropertySource that only has properties in random.*.
12、Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants)
13、Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants)
14、Applicat ion properties outside of your packaged jar (application.properties and YAML variants).
15、Application properties packaged inside your jar (application.properties and YAML variants).
16、@PropertySource annotations on your @Configuration classes.
17. Default properties (specified using SpringApplication.setDefaultProperties).

Load order of spring boot configuration properties: 1. Developer tool `Devtools` global configuration parameters; 2. The parameters specified by the `@TestPropertySource` annotation on the unit test; 3. The parameters specified by the `@SpringBootTest` annotation on the unit test; 4. The parameters specified by the command line, such as `java -jar springboot.jar –name= “Java technology stack”`; 5. `SPRING_APPLICATION_JSON` in the command line specifies parameters, such as `java -Dspring.application.json='{“name”:”Java technology stack”}’ -jar springboot.jar`6, `ServletConfig` initialization parameters; 7, `ServletContext` initialization parameters; 8, JNDI parameters (such as `java:comp/env/spring.application.json`); 9, Java system parameters (source: `System.getProperties()` ); 10. Operating system environment variable parameters; 11. `RandomValuePropertySource` random number, only matching: `ramdom.*`; 12. Configuration file parameters outside the JAR package (`application-{profile}.properties(YAML)`) 13. The configuration file parameters inside the JAR package (`application-{profile}.properties (YAML)`) 14. The configuration file parameters outside the JAR package (`application.pro perties (YAML)`) 15. The configuration file parameters in the JAR package (`application.properties (YAML)`) 16. The parameters loaded by the `@PropertySource` annotation on the `@Configuration` configuration file; 17, the default parameters (via ` SpringApplication.setDefaultProperties` specified);

Leave a Comment

Your email address will not be published.