网站建设的服务器,wordpress知更鸟主题,公司宣传页的样板,用flash做网站教程大家好#xff0c;我是升仔 在微服务架构中#xff0c;统一的配置管理是维护大规模分布式系统的关键。Spring Cloud Config为微服务提供集中化的外部配置支持#xff0c;它可以与各种源代码管理系统集成#xff0c;如Git、SVN等。本文将详细介绍如何搭建配置服务器、管理客…大家好我是升仔 在微服务架构中统一的配置管理是维护大规模分布式系统的关键。Spring Cloud Config为微服务提供集中化的外部配置支持它可以与各种源代码管理系统集成如Git、SVN等。本文将详细介绍如何搭建配置服务器、管理客户端配置和动态刷新配置。 搭建配置服务器 基本原理 Spring Cloud Config Server作为中心化的配置服务器它从源代码管理系统中读取配置文件然后提供给客户端应用。原理图如下 步骤和代码 添加依赖在项目的pom.xml文件中添加Config Server的依赖。 dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-config-server/artifactId
/dependency启用Config Server在应用的主类上添加EnableConfigServer注解。 SpringBootApplication
EnableConfigServer
public class ConfigServerApplication {public static void main(String[] args) {SpringApplication.run(ConfigServerApplication.class, args);}
}配置文件在application.yml中配置Git仓库地址。 server:port: 8888spring:cloud:config:server:git:uri: [Git仓库地址]clone-on-start: true客户端配置管理 配置客户端 添加依赖在客户端应用的pom.xml中添加Config Client的依赖。 dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-config/artifactId
/dependency配置bootstrap.yml客户端应用需要在bootstrap.yml文件中指定Config Server的地址。 spring:application:name: client-appcloud:config:uri: http://localhost:8888读取配置 在客户端应用中可以直接通过Value注解读取配置 RestController
public class ConfigClientController {Value(${some.config})private String someConfig;GetMapping(/getConfig)public String getConfig() {return someConfig;}
}动态刷新配置 Spring Cloud Config支持在不重启服务的情况下刷新配置。 添加依赖在客户端应用中添加spring-boot-starter-actuator依赖。 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId
/dependency使用RefreshScope在需要动态刷新的Bean上添加RefreshScope注解。 RestController
RefreshScope
public class ConfigClientController {// ...
}触发刷新通过POST请求/actuator/refresh端点来刷新配置。 curl -X POST http://localhost:8080/actuator/refresh最后说一句求关注求赞别白嫖
最近无意间获得一份阿里大佬写的刷题笔记一下子打通了我的任督二脉进大厂原来没那么难。
这是大佬写的7701页的BAT大佬写的刷题笔记让我offer拿到手软
本文已收录于我的技术网站next-java.com, 有大厂完整面经工作技术等经验分享
求一键三连点赞、分享、收藏
点赞对我真的非常重要在线求赞加个关注非常感激