这部分内容主要对应官网文档的第24部分Externalized Configuration,我也不知道怎么来准确翻译这个东西。这块涉及到的是配置文件中的环境变量的相关内容。
按照官方的意思是,Spring Boot提供了多种换取环境变量或者配置信息的方式。如properties 文件YAML文件,环境变量和客户端指令等。你可以通过@Value注解和@ConfigurationProperties来获取这些信息。
废话少说,我们来看下具体内容,优先级依次降低的:
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 packa