SpringCloud学习-part38 配置中心之客户端与动态刷新
程序员文章站
2024-03-20 22:32:46
...
文件结构
bootstrap
server:
port: 3355
spring:
application:
name: config-client
cloud:
#Config客户端配置
config:
label: master # 分支名称
name: config #配置文件名称
profile: dev # 读取后缀名称(如前面:master分支上config-dev.yml的配置文件)
uri: http://localhost:3344 #配置中心地址k
inetutils:
timeout-seconds: 10
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka
# 暴露监控点
management:
endpoints:
web:
exposure:
include: "*"
base-path: /monitor
pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>cloud2020</artifactId>
<groupId>com.ezerbel.cloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-config-center-3355</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
controller
/**
* @Author: EzerbelCN
* @Date: 2020/7/27 5:01
*/
// 将配合信息以rest接口的形式暴露
@RestController
@RefreshScope
public class ConfigClientController
{
@Value("${config.info}")
private String configInfo;
@RequestMapping("/configInfo")
public String getConfigInfo()
{
return configInfo;
}
}
主函数入口
/**
* @Author: EzerbelCN
* @Date: 2020/7/27 4:44
*/
@SpringBootApplication
@EnableEurekaClient
public class ConfigClientMain3355 {
public static void main(String[] args){
SpringApplication.run(ConfigClientMain3355.class,args);
}
}
启动测试
测试刷新
在git上提交配置文件的修改之后,需要向目标客户端发送post请求,refresh刷新!注意前面的配置中,默认的actuator被我改成了monitor
curl -X POST "http://localhost:3355/monitor/refresh"
下一篇: iOS中内联函数的使用