config 可以配置在数据库或本地 git 以及远程 git 上,本文介绍配置在码云上,github 同理,但是 github 网速堪忧,读者可自行尝试,下文给出基本的配置代码和截图。解决的痛点就是项目不用停掉,就能更换配置。
服务端:
1、pom 依赖如下,继承项目的父类工程,具体配置看本站 springcloud 其他文章有介绍
所有包都需要,消息总线的作用即配置中心拉去到数据会通过消息总线更新其他服务引用的配置
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- 消息总线 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
2、application 启动加上注解
注册到 eureka,和启用 config 服务配置
3、配置文件
重点配置远程 git 的地址,用户和密码,下一篇介绍客户端的配置
正文完