SpringBoot外部化配置(一)

这章会讲概念(其实就是翻译),接下来会有实际的操作

参考:https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config
一、外部化部署格式
可以使用属性文件,YAML文件,环境变量和命令行参数来外部化配置

Spring Boot使用一个非常特殊的PropertySource顺序,该顺序旨在允许合理地覆盖值。按以下顺序考虑属性(优先级从高到低):

  1. 在$HOME/.config/spring-boot目录里的Devtools 全局设置属性 when devtools is active.
  2. tests里的@TestPropertySource 注解.
  3. 测试中的properties属性. Available on @SpringBootTest and the test annotations for testing a particular slice of your application.
  4. 命令行参数
  5. 来自SPRING_APPLICATION_JSON的属性(嵌入在环境变量或系统属性中的内联JSON).
  6. ServletConfig初始化参数
  7. ServletContext 初始化参数.
  8. 来自java:comp/env的JNDI 属性.
  9. Java系统属性 (System.getProperties()).
  10. OS 环境变量.
  11. 一个只在random.*里的RandomValuePropertySource.
  12. 打包在jar之外的特定于配置文件的应用程序属性(application-{profile}.properties和YAML variants).
  13. 打包在jar中的特定于配置文件的应用程序属性 (application-{profile}.properties和YAML variants).
  14. 打包在jar之外的应用程序属性 (application.properties 和YAML variants).
  15. 打包在jar中的应用程序属性 (application.properties 和YAML variants).
  16. 声明在被@Configuration注解的类上的@PropertySource. 请注意,在刷新应用程序上下文之前,不会将此类属性源添加到Environment中。在此时配置某些属性(如logging.*和spring.main.*在刷新开始之前先读取)为时已晚。
  17. 默认属性 (通过SpringApplication.setDefaultProperties指定设置).

你可能感兴趣的:(springboot,spring,boot)