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

相關文章
相關標籤/搜索