准备:搭建一个服务注册中心,一个配置中心,和一个获取配置的客户端。
提前安装RabbitMQ官网下载 https://www.rabbitmq.com/install-windows.html
git上准备一个文件用做测试
一、Config-Server(配置中心)配置
1.添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
2.修改配置文件application.yml文件
server:
port: 8085
# servlet:
# context-path: #访问项目前缀
spring:
application:
name: config-server #服务注册中心的名称
cloud:
config:
label: master
server:
git:
uri: https://github.com/zhujw0/springCloud-config/
search-paths: config
rabbitmq: #本地环境不需要配置mq,但是需要启动mq,Springboot会自动连接本地mq
host: localhost
port: 5672
username: guest
password: guest
eureka:
client:
service-url:
defaultZone: http://www.eureka-server.com:1111/eureka/ #对应Eureka-server中的url
instance:
hostname: www.client.com
management: #暴露/bus-refresh接口
endpoints:
web:
exposure:
include: "*"
# curl -X POST http://www.client.com:8085/actuator/bus-refresh cmd窗口输入,模拟post请求
3.启动类添加注解 @EnableConfigServer
二、Config Client端配置(测试获取Config-Server服务端获取的git配置)
1.添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>