1、pom.xml依赖
dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-kafka</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</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-bootstrap</artifactId> </dependency>
2、config注解
3、配置git地址(配置文件存放git位置)
下图uri为路径
- application: 表示微服务名称,即配置的spring.application.name
- profile: 表示当前的环境,local、feature、dev、test、prod
- label: 表示git仓库分支,feature、develop、test、master,当然默认的话是master
-
在启动Config Server后去请求获取Git Repo中的配置文件时有以下几种请求形式。
1
2
3
4
5
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
4、设置kafka或MQ(config通过MQ通知客户端配置文件更改)
spring.config.stream.default-binder: kafka
spring.kafka.bootstrap-servers: - 139.159.157.32:9092
浏览器输入ip:port/配置文件名字测试是否成功。