如何分門別類的放置yml文件,被多個工程引用,避免全部堆積在一個application.yml中
一、config-server
項目依賴:
<code>implementation('org.springframework.cloud:spring-cloud-config-server')/<code>
Spring Cloud Config Server為外部配置提供了一個基於HTTP資源的API。通過使用@EnableConfigServer註釋,服務器可嵌入到Spring Boot應用程序中。因此,以下應用程序是配置服務器:
<code>@SpringBootApplication @EnableConfigServer public class ConfigServer { public static void main(String[] args) { SpringApplication.run(ConfigServer.class, args); } }/<code>
application.yml配置方案之一:
<code>spring: cloud: config: server: git: uri: ${GIT_URL:http://xxxx/xxxx/xxx/gityml.git} username: user password: passwd searchPaths: '**/*'/<code>
二、gityml倉庫配置圖解
三、SpringBoot項目配置實例
項目依賴:
<code>implementation('org.springframework.cloud:spring-cloud-starter-config')/<code>
bootstrap.yml配置:
<code>spring: cloud: config: uri: ${CONFIG_SERVER_URL:http://system-service-config} #配置服務的訪問地址 fail-fast: true #鏈接不上配置中心,則停止服務 label: ${GIT_LABEL:dev} #(git項目分支名稱) 環境配置 不同環境使用不同配置,默認是開發環境/<code>
關鍵字: org application 配置