springcloud config简单介绍

config-server
yml配置文件

server:
  port: 8769

# 从git 仓库读取配置文件的配置项
spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/javaStudyFree/config-server.git  #git仓库地址,带不带.git都行
          #searchPaths: aa  不知道有什么用,可以不用配置
          #username:    共有仓库用户和密码可以不配置
          #password:
      label: master
  application:
    name: config-server

git仓库截图
在这里插入图片描述
git中yml内容
在这里插入图片描述

访问http://localhost:8769/master/config-client-dev.yml出现数据,代表成功,其中master代表git的label,config-client-dev.yml代表仓库下的文件名称(只能在仓库下,不能在仓库的文件夹下,仓库的文件夹目前不知道怎么配置)

config-client
bootstrap.yml

spring:
  application:
    name: config-client  #name和active使用-相连组成config-client-dev,代表访问仓库的文件的名称
  cloud:
    config:
      uri: http://localhost:8769
      fail-fast: true  #读取不到执行快速失败
  profiles:
    active: dev
server:
  port: 8762

主启动类

@SpringBootApplication
@RestController
public class ConfigClientApplication {
    
    

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

	@Value("${foo}")
	String foo;
	@RequestMapping(value = "/foo")
	public String hi(){
    
    
		return foo;
	}
}

访问http://localhost:8762/foo出现数据代表成功

猜你喜欢

转载自blog.csdn.net/weixin_44892460/article/details/108303557