Spring Boot 中application.yml與bootstrap.yml的區別

其實yml和properties文件是同樣的原理,且一個項目上要麼yml或者properties,二選一的存在。git

推薦使用yml,更簡潔。spring

bootstrap與application
1.加載順序
這裏主要是說明application和bootstrap的加載順序。bootstrap

bootstrap.yml(bootstrap.properties)先加載
application.yml(application.properties)後加載
bootstrap.yml 用於應用程序上下文的引導階段。app

bootstrap.yml 由父Spring ApplicationContext加載。加密

父ApplicationContext 被加載到使用 application.yml 的以前。.net

2.配置區別
bootstrap.yml 和application.yml 均可以用來配置參數。server

bootstrap.yml 能夠理解成系統級別的一些參數配置,這些參數通常是不會變更的。
application.yml 能夠用來定義應用級別的,若是搭配 spring-cloud-config 使用 application.yml 裏面定義的文件能夠實現動態替換。
使用Spring Cloud Config Server時,應在 bootstrap.yml 中指定:blog

spring.application.name
spring.cloud.config.server.git.uri
一些加密/解密信息
實例:ip

bootstrap.ymlit

spring: application: name: service-a cloud: config: uri: http://127.0.0.1:8888 fail-fast: true username: user password: ${CONFIG_SERVER_PASSWORD:password} retry: initial-interval: 2000 max-interval: 10000 multiplier: 2 max-attempts: 10--------------------- 原文:https://blog.csdn.net/jeikerxiao/article/details/78914132

相關文章
相關標籤/搜索