SpringCloud Config服务端配置、配置读取规则

SpringCloud Config服务端配置

用自己的GitHub账号在GitHub上新建一个名为microservicecloud-config
的新Repository:

获取Repository的http链接

本地硬盘目录上新建git仓库并clone:

在这里插入图片描述

在本地D:\44\mySpringCloud\microservicecloud-config里面新建一个application.yml:

spring:
  profiles:
    active:
      - dev

---
spring:
  profiles: dev # 开发环境
  application:
    name: microservicecloud-config-zhang-dev
---
spring:
  profiles: test # 测试环境
  application:
    name: microservicecloud-config-zhang-test
    

将上一步的YML文件推送到github上:

  • git add .
  • git commit -m “init yml”
  • git push origin master

新建Module模块microservicecloud-config-3344
它即为Cloud的配置中心模块:

引入依赖:

<dependencies>
        <!-- Spring Cloud Config -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>

        <!-- 图形化监控 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!-- 熔断 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>springloaded</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
    </dependencies>

application.yml

server:
  port: 3344

spring:
  application:
    name: microservicecloud-config
  cloud:
    config:
      server:
        git:
          uri: https://github.com/xxx/microservicecloud-config.git #github仓库名字

主启动类Config_3344_StartSpringCloudApp:

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

修改hosts文件,增加映射:

127.0.0.1  config-3344.com

测试通过Config微服务是否可以从GitHub上获取配置内容:

启动微服务3344:

访问:http://config-3344.com:3344/application-dev.yml
在这里插入图片描述

访问:http://config-3344.com:3344/application-test.yml
在这里插入图片描述

访问:http://config-3344.com:3344/application-xxx.yml(不存在的配置)
在这里插入图片描述

配置读取规则

在这里插入图片描述

/{application}-{profile}.yml

  • http://config-3344.com:3344/application-dev.yml
  • http://config-3344.com:3344/application-test.yml
  • http://config-3344.com:3344/application-xxx.yml(不存在的配置)

/{application}/{profile}[/{label}]

  • http://config-3344.com:3344/application/dev/master
  • http://config-3344.com:3344/application/test/master
  • http://config-3344.com:3344/application/xxx/master

/{label}/{application}-{profile}.yml

  • http://config-3344.com:3344/master/application-dev.yml
  • http://config-3344.com:3344/master/application-test.yml
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值