该方案需使用外部配置进行验证,启动命令如下例:
java -jar xxx.war --spring.profiles.active=local --spring.config.location=E:\ideaFile
使用@RefreshScope
1、导入依赖
添加如下依赖:
<!--refresh配置-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<!--监控–>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2、添加对应配置
设置开放refresh接口,如添加以下配置,配置Actuator开放/actuator/refresh接口。详细Actuator端点用法参考下文 《附录一、启用和禁用Actuator端点》
management.endpoints.web.exposure.include = refresh
# 默认为true,不需要开启任何端点时设置为