zoukankan      html  css  js  c++  java
  • 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规则,如下:

     

  • 相关阅读:
    SVN更新的时候前面的子母的意思(A C D M G U R I)
    SQL总结(一)基本查询
    eclipse中如何打开工作空间里面已经有的项目
    java for循环的几种写法
    Eclipse自动生成作者、日期注释等功能设置
    linux任务计划及周期性任务计划
    进程管理工具使用
    Btrfs管理及应用
    LVM基本应用,扩展及缩减实现
    Linux-RAID
  • 原文地址:https://www.cnblogs.com/ibcdwx/p/14447736.html
Copyright © 2011-2022 走看看