SpringCloud Config 使用Git的应用实例

如何分门别类的放置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仓库配置图解


SpringCloud Config 使用Git的应用实例

注意:yml文件名称,application.yml代表公共的,所有项目都会获取


三、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>


分享到:


相關文章: