SpringCloudConfig

欢迎光临我的博客[http://poetize.cn],前端使用Vue2,聊天室使用Vue3,后台使用Spring Boot

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

组成

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
          basedir: E:\Java\config\basedir    #可以使用这个配置项来指定本地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:
        #/{label}/{name}-{profiles}.yml
        name: user    #一般以服务名来命名
        profile: dev    #一般作为环境标识,开发环境(dev)、测试环境(test)、生产环境(product)
        label: master
        uri: http://127.0.0.1:9998

假如在不同环境下有很多共用的配置,我们可以再创建一个user.yml用来存放共同配置
springcloud-config取配置时,会将你的对应环境配置与user.yml合并后再返回(前缀name相同)。
posted @ 2019-09-01 09:56  LittleDonkey  阅读(169)  评论(0编辑  收藏  举报