1.添加依赖
?
|
1
2
3
4
|
<dependency>
<groupid>org.springframework.cloud</groupid>
<artifactid>spring-cloud-config-server</artifactid>
</dependency>
|
2.启动类,需要添加@enableconfigserver
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
import org.springframework.boot.springapplication;
import org.springframework.boot.autoconfigure.springbootapplication;
import org.springframework.cloud.config.server.enableconfigserver;
/**
* @author fusw
*/
@springbootapplication
@enableconfigserver
public class configcenterapplication {
public static void main(string[] args) {
springapplication.run(configcenterapplication.class, args);
}
}
|
3.配置文件
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
eureka.instance.appname=base-iov-config
security.user.name=test
security.user.password=test
# gitlab 的配置方式,必须有 .git 后缀
# 配置默认 git 仓库的地址
spring.cloud.config.server.git.uri=http://xxxx/config-repo.git
# git 仓库地址下的相对地址,可以配置多个,用“,”分割
spring.cloud.config.server.git.search-paths=*
#配置中心clone仓库配置文件后存放的地址
spring.cloud.config.server.git.basedir=/data/deploy/config-repo
spring.cloud.config.server.git.force-pull=true
# git 仓库的账号
spring.cloud.config.server.git.username=test
# git 仓库的密码
spring.cloud.config.server.git.password=test
# 配置 其它git 仓库的地址 spring.cloud.config.server.git.repos.x.uri, iot为例
spring.cloud.config.server.git.repos.iot.uri=http://xxxx/iot/config-repo.git
spring.cloud.config.server.git.repos.iot.search-paths=*
spring.cloud.config.server.git.repos.iot.basedir=/data/deploy/config-repo
spring.cloud.config.server.git.repos.iot.force-pull=true
# git 仓库的账号
spring.cloud.config.server.git.repos.iot.username=test
# git 仓库的密码
spring.cloud.config.server.git.repos.iot.password=test
#前缀一定要配置,用来和默认仓库区分
spring.cloud.config.server.git.repos.iot.pattern=iot*
#注册中心
eureka.client.serviceurl.defaultzone=http://xxx/eureka/
|
二、git 存放配置的仓库
创建一个git仓库用来存放各项目配置,可以在项目一级目录根据项目创建文件夹(各项目文件夹的名称可以随便起,config配置中心只根据配置文件名找配置),然后各个项目文件夹存放不同环境的配置文件,
例如:
iot-testproject-dev.yml
iot-testproject-prd.yml
iot-testproject-test.yml
最好不要放置test.yml类似的默认配置,如果在各个项目配置文件中没有用spring.profiles.active指明使用的配置文件,那么会加载默认的配置文件。
三、各个springcloud的项目配置接入配置中心
在resource下的bootstrap.properties配置文件中,配置中心的相关配置如下
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# 使用默认仓库的配置文件
spring.cloud.config.name=testproject
# 使用iot厂库的配置文件
#spring.cloud.config.name=iot-testproject
#使用哪个环境的配置文件,和上面的配置配合,决定了使用哪一个配置文件:testproject -test.yml
spring.cloud.config.profile=test
# 对应 存放配置文件仓库的git分支
spring.cloud.config.label=master
spring.cloud.config.username=test
spring.cloud.config.password=test
# 开启 config 服务发现支持
spring.cloud.config.discovery.enabled=true
# 指定 server 端的 name,也就是 server 端 spring.application.name 的值
spring.cloud.config.discovery.serviceid=base-iov-config
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。
原文链接:https://segmentfault.com/a/1190000018437089
相关文章
猜你喜欢
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-29 77
-
2025-05-29 69
-
2025-05-29 106
-
2025-05-25 79
-
2025-05-25 39
热门评论

