将某个微服务的配置文件上传到一个git服务器
创建SpringCloud Config服务
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>tensquare_parent</artifactId>
<groupId>com.tensquare</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.tensquare</groupId>
<artifactId>tensquare_config</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
</project>
server:
port: 12000
spring:
application:
name: tensquare-config
cloud:
config:
server:
git:
uri: https://gitee.com/xu_yu/springcloud_config_test.git
package com.tensquare.config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
/**
* @auther Mr.Liao
* @date 2019/8/11 15:38
*/
@SpringBootApplication
@EnableConfigServer
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
启动服务,通过浏览器访问:http://localhost:12000/article-dev.yml
修改微服务article项目,删除原来的application.yml配置文件,新建bootstrap.yml
spring:
cloud:
config:
name: article # 配置文件名-前的字段
profile: dev # 配置文件名-后的字段
label: master
uri: http://127.0.0.1:12000
添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
重启服务,测试获取数据