新建模块-添加依赖 -在启动类上添加@EnableConfigServer
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
配置文件
spring:
application:
name: cloud-config-server
cloud:
config:
server:
git:
uri: https://github.com/87956992/spring-cloud-config.git
search-paths:
- spring-cloud-config
username: 87956992@qq.com
password: sfy@103252203569
basedir: D:\_my-project\cloud-edu\springCloud-config\location
label: master
创建新模块测试配置中心是否生效 端口3355
添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
配置文件(bootstrap.yml)
spring:
application:
name: cloud-config-client
cloud:
config:
label: master
name: config
profile: dev
uri: http://localhost:3344
测试生效
问题1,修改配置文件后每次需重启项目
解决1 在配置文件添加
# 暴露检测断点
management:
endpoints:
web:
exposure:
include: "*"
在代码需要刷新的类上添加注解@RefreshScope
手动发送请求 curl -X POST "http://localhost:3355/actuator/refresh"
3355项目配置生效
问题一缺点在下一随笔进一步完善
原文:https://www.cnblogs.com/shufeiyang/p/13061218.html