1 编写config server端(配置中心)
1.1 引入依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
</dependency>
</dependencies>
1.2 编写配置文件(bootstrap.yml)
server:
port: 8080
spring:
application:
name: config-server-svn
profiles:
active: subversion #使用svn作为配置仓库,必须显示声明profiles.active=subversion,不然还是用的git
cloud:
config:
server:
svn:
uri: http://192.168.1.100/XXXX/springconfig/SpringCloudConfig #配置svn仓库地址
searchPaths: dev,test,prod #配置仓库路径
username: spring #访问svn仓库的用户名
password: XXXXXX #访问svn仓库的用户密码
basedir: /data #默认在系统临时目录下面,需要调整一下避免临时文件被系统自动清理
label: trunk #配置svn的分支
1.3 此时我的svn目录如下
--dev
--application-dev.yml
--wechat-dev.yml
--test
--application-test.yml
--wechat-test.yml
--prod
--application-prod.yml
--wechat-prod.yml
2 编写config client端
2.1 引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
2.2 编写配置文件(bootstrap.yml)
spring:
application:
name: wechat
cloud:
config:
label:
profile: dev #spring.cloud.config.profile# #dev开发环境配置文件,test测试环境配置文件,prod生产环境配置文件
uri: http://localhost:8080/ #指明配置服务中心的网址
3 启动config server和config client
首先启动config server工程,然后启动config client工程,即可看到config client工程的控制台
打印出读取dev文件夹下的wechat-dev.yml配置文件。
欢迎关注我的微信公众号,不定期更新文章和大家一起学习共勉