1.為什么要使用config
- 集中管理
- 不通環(huán)境不通配置
- 運行期間動態(tài)調整配置
- 自動刷新
2.用法入門
- 導入pom
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
- 啟動類添加注解
@EnableConfigServer
- 修改application.yml
spring:
cloud:
config:
server:
git:
uri: https://github.com/jiaofanting/spring-cloud-config-repo/
server:
port: 8080
這個uri是我git目錄放的一個application.yml 路徑秆麸,打開是404,因為它不是一個有效的鏈接,它只是說明了 application.yml文件放在哪里供璧。
- 看官方文檔說明
The HTTP service has resources in the form:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
where the "application" is injected as the spring.config.name in the SpringApplication (i.e. what is normally "application" in a regular Spring Boot app), "profile" is an active profile (or comma-separated list of properties), and "label" is an optional git label (**defaults to "master".**)
截圖更清晰
注意中間有個- 耀盗,對照文檔看效果