spring-cloud 2.2.5 config
一、config-server
1. pom.xml
<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>-->
<!--admin客户端 -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
</dependencies>
2.配置
server:
port: 8889
spring:
cloud:
config:
server:
git:
uri: https://gitee.com/zhongbangchao/all-config.git
search-paths: '{application}'
username: *****
password: *****
application:
name: spring-cloud-config
eureka:
client:
service-url:
defaultZone: http://localhost:9991/eureka/
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: ALWAYS
二、config-client
1. pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--admin客户端 -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
</dependencies>
2. 配置
spring:
application:
name: instance
cloud:
config:
uri: http://localhost:8889
name: git-base-config,${spring.application.name}
label: master
启动客户端会去配置中心拿指定的配置文件
name 这里如果一个实例放在一个文件夹中,文件夹名称与文件名前缀不一致会导致读取不到
例如:
spring.clouf.config.name=instance
git地址中instance.yml 文件放在instance1 文件夹下, 这样会读取不到这个文件。
把instance1 文件夹改为 instance 解决问题。