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的地址,用户和密码,下一篇介绍客户端的配置

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注