Spring Cloud Config为分布式系统中的外部配置提供服务器和客户端支持。使用Config Server,您可以在所有环境中管理应用程序的外部属性 ,通常情况下我们可以把需要管理的配置文件放置在svn或者git上进行做统一的配置仓库。

 

二 创建git远程仓库远程仓库中创建所需的配置文件

  本例子中是demo-local.yml , 配置文件内容如下:

  

student:
  name: test
  age: 28
View Code

 

三 创建config-server端

1) 创建gradle模块config-server并添加gradle依赖

dependencies {
    compile('org.springframework.cloud:spring-cloud-config-server')
}
View Code

2)编辑application.yml配置

server:
  port: 8000
spring:
  cloud:
    config:
      server:
        git:
          uri: git@gitlab.com:xxxx/config.git
      enabled: true
  profiles:
    active: local
View Code

 其中spring.cloud.config.server.git是配置远程仓库的地址,如果不使用SSH协议请配置username和password属性

3)编写启动类

package com.bdqn.lyrk.config;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;


@SpringBootApplication
@EnableConfigServer
public class ConfigServer {

    public static void main(String[] args) {
        SpringApplication.run(ConfigServer.class, args);
    }
}
View Code

注意在启动类上添加@EnableConfigServer注解

四 创建config-client端

 1)创建gradle模块demo-server并添加gradle依赖

dependencies{
    compile('org.springframework.cloud:spring-cloud-starter-config')
}
View Code

相关文章:

  • 2021-10-11
  • 2022-12-23
  • 2022-12-23
  • 2021-07-24
  • 2021-09-29
  • 2021-06-13
  • 2022-12-23
猜你喜欢
  • 2022-01-10
  • 2021-10-21
  • 2021-09-25
  • 2021-06-29
  • 2022-12-23
  • 2021-09-14
  • 2021-12-19
相关资源
相似解决方案