SpringCloudConfig

方便服务配置文件统一管理,实时更新

组成

spring cloud config组件中,分两个角色,一是config server,二是config client

Config Server是一个可横向扩展、集中式的配置服务器,它用于集中管理应用程序各个
环境下的配置,默认使用Git存储配置文件内容,也可以使用SVN存储,或者是本地文件
存储。

Config ClientConfig Server的客户端,用于操作存储在Config Server中的配置内容。
微服务在启动时会请求Config Server获取配置文件的内容,请求到后再启动容器

配置中心微服务

依赖

<dependency>
    groupId>org.springframework.cloud</groupId>
    artifactId>spring-cloud-config-server</artifactId>
</dependency>

启动类

@SpringBootApplication
@EnableConfigServer
public class ConfigApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigApplication.class, args);
    }
}

application.yml

server:
  port: 9998
spring:
  application:
    name: tensquare‐config
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/ld/tensquare‐config.git

#git的用户名
spring.cloud.config.server.git.username=username
#git的密码
spring.cloud.config.server.git.password=password

配置客户端

依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

bootstrap.yml

spring:
  cloud:
    config:
        name: tensquare
        profile: user
        label: master
        uri: http://127.0.0.1:9998

猜你喜欢

转载自www.cnblogs.com/loveer/p/11441493.html