服务器仓库config文件,创建配置中心服务端(Spring Cloud Config)

创建配置中心服务端

3b9e64f0fe5ed7436717e529f6b62525.png

6fc3d4f27bd8ed52d47b6940004ebda3.png

8c249afa744ea129dbe2e0418433f6ad.png

534ac0ee3dfe7031bfbd2a1d197183b0.png

创建好项目后添加配置文件内容

server.port=9004

spring.application.name=spring-cloud-config-server-01

#git仓库地址

spring.cloud.config.server.git.uri=http://git.home/test/config-depot.git

#仓库内的相对路径

spring.cloud.config.server.git.search-paths=/config

#git用户名

spring.cloud.config.server.git.username=sunweisheng

#git密码

spring.cloud.config.server.git.password=********

添加开启配置中心的注解(SpringCloudConfigServerApplication.java)

@SpringBootApplication

//启动配置中心

@EnableConfigServer

public class SpringCloudConfigServerApplication {

public static void main(String[] args) {

SpringApplication.run(SpringCloudConfigServerApplication.class, args);

}

}

在git仓库里添加配置文件

Git仓库名称:config-depot,仓库根目录下创建文件夹config,在config目录下创建配置文件ConfigDepot-Test.properties,配置文件内容:bluersw.config=Test-1

9e8571acb456a181e2ea17977ee05aee.png

fba7c81284abedd7c35ffc7be7380a9d.png

测试配置中心

在浏览器中访问127.0.0.1:9004/ConfigDepot/Test,返回Json格式的配置文件内容,证明配置中心读取Git仓库内容成功。

1dec56d7fbb3d8c7279b12cc39655345.png

{

"name":"ConfigDepot",

"profiles":["Test"],

"label":null,

"version":"e3fdd0937bba0ad2df3eefe09ac3ab33ca09397b",

"state":null,

"propertySources":[{

"name":"http://git.home/test/config-depot.git/config/ConfigDepot-Test.properties",

"source":{

"bluersw.config":"Test-1"

}

}]

}

仓库里的配置文件路径可以转化为REST接口在配置中心中访问,转化规则:

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

/{application}-{profile}.yml

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

/{application}-{profile}.properties

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

PS:配置中心读取Git仓库信息没有缓存,如果配置文件的内容改为Test-3,直接刷新页面就可以看到刚改的值(Test-3)。

源码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值