当前位置: 首页 > news >正文

慈溪市网站建设深圳市营销型网站建设

慈溪市网站建设,深圳市营销型网站建设,wordpress内核源码,构建企业门户网站的方法Spring Cloud Config: 了解、原理和使用 Spring Cloud Config 是 Spring Cloud 生态系统中的一个重要组件#xff0c;它提供了一种分布式配置管理的解决方案#xff0c;能够集中管理应用程序的配置#xff0c;支持多种后端存储#xff0c;如 Git、SVN、本地文件系统、Vaul…Spring Cloud Config: 了解、原理和使用 Spring Cloud Config 是 Spring Cloud 生态系统中的一个重要组件它提供了一种分布式配置管理的解决方案能够集中管理应用程序的配置支持多种后端存储如 Git、SVN、本地文件系统、Vault 等。在本文中我们将介绍 Spring Cloud Config 的概念、原理和使用方法并提供一些代码示例。 了解 Spring Cloud Config Spring Cloud Config 通过将应用程序配置集中管理使得应用程序的配置更加易于管理和维护。它通过将配置存储在远程仓库中如 Git并提供 REST API 来访问配置从而实现了分布式配置管理。Spring Cloud Config 还支持配置的版本管理可以根据不同的环境、不同的应用程序等来管理配置从而实现了应用程序的多环境部署。 Spring Cloud Config 有两个核心组件 Config Server配置服务器用于存储和管理应用程序的配置。Config Client配置客户端用于从 Config Server 中获取配置。 Spring Cloud Config 的原理 Spring Cloud Config 的核心原理是将应用程序的配置存储在远程仓库中并将其作为一个 REST API 来访问。Config Server 会自动从远程仓库中获取配置然后将其返回给 Config Client。Config Client 可以通过 HTTP 或 HTTPS 协议来访问 Config Server并获取应用程序的配置。 Spring Cloud Config 支持多种仓库类型如 Git、SVN、本地文件系统、Vault 等。其中Git 是最常用的仓库类型。在使用 Git 作为配置仓库时Config Server 会自动从 Git 仓库中获取配置文件并将其转换为一个 REST API 来访问。配置文件的命名规则是 a p p l i c a t i o n − {application}- application−{profile}.yml 或 a p p l i c a t i o n − {application}- application−{profile}.properties其中 a p p l i c a t i o n 是应用程序的名称 {application} 是应用程序的名称 application是应用程序的名称{profile} 是应用程序的环境。 如何使用 Spring Cloud Config 下面我们来介绍如何使用 Spring Cloud Config 来管理应用程序的配置。 创建 Config Server 首先我们需要创建一个 Config Server用于存储和管理应用程序的配置。可以使用 Spring Boot 来创建 Config Server只需要添加以下依赖 dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-config-server/artifactId /dependency然后在应用程序的启动类上添加 EnableConfigServer 注解即可启动 Config Server SpringBootApplication EnableConfigServer public class ConfigServerApplication {public static void main(String[] args) {SpringApplication.run(ConfigServerApplication.class, args);} }默认情况下Config Server 会从 Git 仓库中获取配置文件。可以通过在 application.yml 文件中添加以下配置来指定 Git 仓库的位置 spring:cloud:config:server:git:uri: https://github.com/spring-cloud-samples/config-repo.git创建 Config Client 接下来我们需要创建一个 Config Client用于从 Config Server 中获取应用程序的配置。可以使用 Spring Boot 来创建 Config Client只需要添加以下依赖 dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-config/artifactId /dependency然后在应用程序的启动类上添加 EnableConfigrationProperties 注解即可启动 Config Client SpringBootApplication EnableConfigurationProperties public class ConfigClientApplication {public static void main(String[] args) {SpringApplication.run(ConfigClientApplication.class, args);} }默认情况下Config Client 会从 Config Server 中获取应用程序的配置。可以通过在 application.yml 文件中添加以下配置来指定 Config Server 的位置 spring:cloud:config:uri: http://localhost:8888获取配置 现在我们已经创建了 Config Server 和 Config Client下面我们来看看如何从 Config Server 中获取应用程序的配置。 我们可以通过在 application.yml 文件中添加以下配置来指定应用程序的名称和环境 spring:application:name: myappprofiles:active: dev这里我们将应用程序的名称设置为 myapp环境设置为 dev。然后在 Config Server 中创建一个名为 myapp-dev.properties 的配置文件内容如下 foobar接下来在 Config Client 中可以通过 Value 注解来获取配置 RestController public class ConfigController {Value(${foo})private String foo;GetMapping(/foo)public String getFoo() {return foo;} }这样当访问 /foo 接口时就可以获取到配置中的 foo 属性了。 配置加解密 在实际使用中我们可能需要对配置进行加解密以保证配置的安全性。Spring Cloud Config 支持配置加解密可以使用 Jasypt 来实现。 首先我们需要在 Config Server 和 Config Client 中添加以下依赖 dependencygroupIdcom.github.ulisesbocchio/groupIdartifactIdjasypt-spring-boot-starter/artifactId /dependency然后在 Config Server 中可以通过在 application.yml 文件中添加以下配置来指定加解密密钥 jasypt:encryptor:password: mysecretkey然后在 Config Server 中创建加密的配置文件可以使用 Jasypt 命令行工具来加密 java -cp jasypt-1.9.3.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI inputfoobar passwordmysecretkey algorithmPBEWithMD5AndDES将加密后的结果保存为 myapp-dev.properties.encrypted 文件。然后在 Config Client 中可以通过在 application.yml 文件中添加以下配置来指定解密密钥 jasypt:encryptor:password: mysecretkey然后在 Config Client 中可以直接获取解密后的配置 RestController public class ConfigController {Value(${foo})private String foo;GetMapping(/foo)public String getFoo() {return foo;} }这样当访问 /foo 接口时就可以获取到解密后的配置中的 foo 属性了。 总结 Spring Cloud Config 是 Spring Cloud 生态系统中的一个重要组件它提供了一种分布式配置管理的解决方案能够集中管理应用程序的配置支持多种后端存储如 Git、SVN、本地文件系统、Vault 等。在本文中我们介绍了 Spring Cloud Config 的概念、原理和使用方法并提供了一些代码示例。希望本文对于了解和使用 Spring Cloud Config 有所帮助。
http://www.hkea.cn/news/14293663/

相关文章:

  • 如何做网站自适应用html5做的美食网站
  • 湖南省军区强军网网站群建设项目6项目网络图怎么看
  • 机关网站建设的作用网站建设内页
  • 网站各个阶段推广昆明建设网站哪家好
  • 做动画在线观看网站做剧情网站侵权吗
  • wordpress中英文网站模板徐州建设工程交易网站
  • 建造师免费自学网站网站视觉首页怎么做
  • 乐山智顶网站建设企业服务中心官网
  • 淘客网站模板九网互联怎么建设网站
  • 电商网站建设行业现状空间中国网站地址多少
  • 莱芜做网站建设的公司关于做网站的问卷调查
  • 最好的产品网站建设用自己的话回答网络营销是什么
  • 买东西网站有哪些网站管理系统
  • 网站建设的公司哪家是上市公司联享品牌网站建设
  • 响应式网站尺寸节点深圳市网络公司
  • app和微网站的对比百度排名
  • 建购物网站怎么建呀wordpress做下载站
  • 南昌网站设计哪家专业好杭州网络推广平台
  • 网站建设中 模版下载河南营销型网站
  • 服装 公司 网站建设软件开发定制平台
  • 免费网站空间怎么办彩视网站建设策划
  • 网站建设的税收编码竹子建站邀请码
  • 国外访问国内网站慢做英文小工具网站赚钱
  • 图片转链接生成器网站深圳 福田网站建设
  • 怎么做网站解析在线设计平台行业环境
  • 柳州网站开发wordpress克隆
  • 福建省住房和城乡建设厅网站校园新主页网站的建设
  • 沈阳网站制作服务网站开发凭证做什么科目
  • 幼教网站建设分析wordpress 添加表格
  • 工作室网站模板新东方烹饪培训学校