server:
port: 8767
spring:
cloud:
config:
server:
git:
uri: http://192.168.3.233/nanjing-springcloud/applicationconfig.git #仓库地址
search-paths: dev #仓库下的子目录
username: root #gitlab用户名
password: MECT888! #gitlab密码
通过/{application}/{profile}就能访问配置文件:application表示配置文件的名字,对应我们上面的配置文件就是application(配置文件统一前缀),profile表示环境(配置文件后面的文件名)。举例:启动配置中心后通过访问:
http://192.168.81.110:8767/application/test/
即可访问配置文件内容
spring:
application:
name: config-client
cloud:
config:
#service-id: config-server #需要注册中心的支持
uri: http://192.168.81.110:8767 #不需要注册中心支持
name: application #代表文件前缀
label: master #分支
profile: test #如果是其他yml,写全名即可,这里的test代表application-test.yml(也代表test.yml)
server:
port: 8766
server:
port: 9999
分别启动eureka-server、config-server、config-client,访问
192.168.81.110:8767/application/test/
得到以下显示结果:
{
"name": "application",
"profiles": [
"test"
],
"label": null,
"version": "c5356fe61e0f2bb8eab7b90323be75ffc1b192db",
"state": null,
"propertySources": [
{
"name": "http://192.168.3.233/nanjing-springcloud/applicationconfig.git/dev/application-test.yml",
"source": {
"server.port": 9999
}
}
]
}
当显示正确的git地址过后即表明配置中心生效,这时访问
http://192.168.81.110:9999/actuator
若出现以下结果则表明配置中心起作用了
{
"_links": {
"self": {
"href": "http://192.168.81.110:9999/actuator",
"templated": false
},
"archaius": {
"href": "http://192.168.81.110:9999/actuator/archaius",
"templated": false
},
......
}
}
访问 http://192.168.81.110:8767/application-test.yml 可以直接输出配置文件内容:
server:
port: 9999