springcloud-Config配置中心搭建

  新建一个模块作为配置中心。具体步骤如下:

  1. 新建一个模块

  2. 加入依赖:

       《主要是这个依赖》 
    <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>cn.aib.springcloud</groupId> <artifactId>springclud-api-common</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>

  3.添加配置(配置中心也算是一个服务模块,也得注册到注册中心上)

server:
  port: 3344
spring:
  application:
    name: cloud-config-center
  cloud:
    config:
      server:
        git:
          uri: https://github.com/XueWen-Yellow/springcloud-config.git //这个是配置文件所在的仓库的地址
          search-paths:
            - springcloud-config  //这个是仓库名
      label: master  //哪个分支,虽然github上面已经是main分支了,目前master还能配置

eureka:
  client:
    service-url:
      defaultZone: http://localhost:7001/eureka

  4.主启动

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

  5.测试。可以访问config暴露出来的接口来获取配置信息,比如:http://localhost:3344/main/config-test.yml;之前是master,现在访问必须是main了

  至于这个访问的URI规则,如下:

 

 

 

posted @ 2021-02-25 16:36  爱编程DE文兄  阅读(126)  评论(0编辑  收藏  举报