config
<!--spring-cloud 整合 config-server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
启动类注解 @EnableConfigServer
application.yml
###服务注册到eureka地址
eureka:
client:
service-url:
defaultZone: http://localhost:8100/eureka
spring:
application:
####注册中心应用名称
name: config-server
cloud:
config:
server:
git:
###git环境地址
uri: https://gitee.com/aokex/FenBuShiPeiZhiWenJian.git
####搜索目录
search-paths:
- gkconfig
####读取分支
label: master
####端口号
server:
port: 8888
client
pom必须配 不然找不到配置文件
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<!-- actuator监控中心 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
controller 加 @RefreshScope 更新配置
bootstrap.yml
spring:
application:
####注册中心应用名称
name: test-config
cloud:
config:
####读取后缀
profile: dev
####读取config-server注册地址
discovery:
service-id: config-server
enabled: true
##### eureka服务注册地址
eureka:
client:
service-url:
defaultZone: http://localhost:8100/eureka
server:
port: 8882
##开启所有监控端点
management:
endpoints:
web:
exposure:
include: "*"
注意 spring.application.name=配置文件前缀
手动刷新 http://127.0.0.1/actuator/refresh