SpringCloud学习笔记(六)—— 配置中心config

1、spring cloud config 介绍

 Spring Cloud Config为分布式系统中的外部配置提供服务器和客户端支持,使用Config Server,您可以在所有环境中管理应用程序的外部属性。客户端和服务器上的概念映射与Spring Environment和PropertySource抽象相同,

 

  因此它们与Spring应用程序非常契合,但可以与任何以任何语言运行的应用程序一起使用。随着应用程序通过从开发人员到测试和生产的部署流程,您可以管理这些环境之间的配置,并确定应用程序具有迁移时需要运行的一切。

 

  服务器存储后端的默认实现使用git,因此它轻松支持标签版本的配置环境,以及可以访问用于管理内容的各种工具。很容易添加替代实现,并使用Spring配置将其插入。

2、环境搭建

2.1、配置中心服务端搭建

2.1.1、 pom

 <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-config-server</artifactId>

</dependency>

2.2.2、application.yml

server:

  port: 3344

spring:

  application:

    name: config-server

  cloud:

    config:

      server:

        git:

          uri:#这里填写仓库地址xxx.git

#git 仓库的账号密码

#username: xxx

#password: xxx

 

2.2.3、程序入口

@EnableConfigServer

@SpringBootApplication

public class ConfigServiceApplication {

 

    public static void main(String[] args) {

        SpringApplication.run(ConfigServiceApplication.class, args);

    }

}

2.2、客户端配置设置

2.2.1、 pom

 <dependency>

            <groupId>org.springframework.cloud</groupId>

            <artifactId>spring-cloud-config-server</artifactId>

</dependency>

<dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

 

这里提一下,为什么需要引入前面的actuctor依赖,因为,我们Client端需要在不重启的情况下,及时更新拉取加载配置中心的改变,然后修改内存中的配置的值。

2.2.2、bootstrap.yml

spring:

   cloud:

      config:

        name: config-client

        profile: test

        label: master

        uri: http://localhost:3344

        #如果配置了eureka,可以选择使用以下方式,无需配置uri

      #discovery:

        # enabled: true

       #这个名字是Config Server端的服务名字,不能瞎写。

         # service-id: config-server

#是否需要权限拉去,默认是true,如果不false就不允许你去拉取配置中心Server更新的内容

management:

  security:

    enabled: false

 

server:

  port: 3355

 

配置以上设置后,启动程序默认拉取代码

猜你喜欢

转载自blog.csdn.net/AlphonesEric/article/details/89047476