1、创建远程仓库,获取远程仓库地址(省略),application.yml

  springcloud 配置中心git 随笔 第1张

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

 

2、创建服务端工程

3、添加依赖

<dependencies>
        <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>
    </dependencies>

4、加注解

  

@EnableDiscoveryClient
@EnableConfigServer //激活对配置中心的支持
@SpringBootApplication
public class SpringCloudConfigServerMqApplication {

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

}

 

5、修改配置application.properties

spring.application.name=spring-cloud-config-server
server.port=8500

spring.cloud.config.server.git.uri=https://***.git
spring.cloud.config.server.git.username=***
spring.cloud.config.server.git.password=***

eureka.client.serviceUrl.defaultZone=http://**:***/eureka/

 

6、请求方式

 

1、application-{profiles}.yml请求
http://192.168.0.131:8500/application-local.yml
http://192.168.0.131:8500/application-test.yml
http://192.168.0.131:8500/application-prod.yml
2、application/{profiles}/{lable}
http://192.168.0.131:8500/application/local/master
http://192.168.0.131:8500/application/test/master
http://192.168.0.131:8500/application/prod/master
3、{lable}/application-{profiles}.yml
http://192.168.0.131:8500/master/application-local.yml
http://192.168.0.131:8500/master/application-test.yml
http://192.168.0.131:8500/master/application-prod.yml

 

7、创建客户端工程

8、添加依赖

  

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

 

9、加注解

@SpringBootApplication
@EnableDiscoveryClient
public class SpringCloudProviderDynastyMqApplication {

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

}

10、修改配置bootstrap.yml

spring:
  application:
    name: dynasty
  cloud:
    config:
      uri: http://192.168.0.131:8500
      profile: prod
      label: master
management:
  endpoints:
    web:
      exposure:
        include: refresh,health,info

11、发送请求

  

12、修改远程仓库的值,使用postman刷新

springcloud 配置中心git 随笔 第2张

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄