spring boot 中 application.yml 和 bootstrap.yml 的区别

bootstrap.yml 在 application.yml 以前加载git

典型的应用场景以下:spring

  • 当使用 Spring Cloud Config Server 的时候,你应该在 bootstrap.yml 里面指定 spring.application.name 和 spring.cloud.config.server.git.uri
  • 和一些加密/解密的信息

技术上,bootstrap.yml 是被一个父级的 Spring ApplicationContext 加载的。这个父级的 Spring ApplicationContext是先加载的,在加载application.yml 的 ApplicationContext以前。bootstrap

为什么须要把 config server 的信息放在 bootstrap.yml 里?app

当使用 Spring Cloud 的时候,配置信息通常是从 config server 加载的,为了取得配置信息(好比密码等),你须要一些提前的或引导配置。所以,把 config server 信息放在 bootstrap.yml,用来加载真正须要的配置信息。加密

参考资料

https://stackoverflow.com/questions/32997352/what-is-the-diference-between-putting-a-property-on-application-yml-or-bootstrap?rq=1#comment64492133_35545152server

相关文章
相关标签/搜索