**Spring Cloud Config 2.2.2** 是一个用于集中化配置管理的组件,它为分布式系统中的微服务提供了外部配置支持

Spring Cloud Config为分布式系统提供外部配置的服务器和客户端支持,允许在所有环境中集中管理应用程序的外部属性。通过Config Server,可以轻松地在从开发到测试再到生产的部署管道中管理不同环境的配置,确保应用程序在迁移时具备运行所需的一切。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Spring Cloud Config 2.2.2 特性与更新

Spring Cloud Config 2.2.2 是一个用于集中化配置管理的组件,它为分布式系统中的微服务提供了外部配置支持。以下是该版本的主要特性与更新内容:

核心特性
  1. 集中化配置管理

    • 提供服务端(Config Server)和客户端(Config Client)支持,集中管理分布式环境下的应用配置。
    • 支持多环境配置文件管理,允许不同环境下的配置文件分别存储和加载。
  2. 版本控制与存储

    • 默认实现基于 Git 仓库,支持配置文件的版本管理。
    • 支持自定义存储后端,如本地文件系统或自定义实现。
  3. 动态刷新配置

    • 支持动态刷新配置,应用程序可以在运行时通过调用 REST 接口或配置中心修改配置文件后自动更新。
  4. 安全性控制

    • 提供基于角色的安全性控制,限制对配置文件的访问权限。
    • 支持配置值的加密和解密,保护敏感信息。
  5. 与 Spring 生态系统集成

    • 无缝与 Spring 应用集成,支持 Spring 环境和 PropertySource 抽象。
    • 支持任何语言开发的程序,不仅限于 Java。
更新内容
  1. Git 后端增强

    • 支持跳过 SSL 证书验证,通过设置 git.skipSslValidation 属性。
    • 支持设置 HTTP 连接超时时间。
    • 支持在 Git URI 中使用占位符(如 {application}{profile}),实现“每个应用一个仓库”或“每个环境一个仓库”的策略。
  2. 多仓库支持

    • 支持模式匹配和多个仓库,可以根据应用名称或环境模式动态加载配置。
  3. 加密与解密

    • 支持远程配置源中的加密内容(以 {cipher} 开头的值),在发送到客户端之前进行解密。
    • 提供 /encrypt/decrypt 端点,用于在配置文件中加密和解密值。
  4. 客户端功能增强

    • 客户端在启动时会从 Config Server 获取配置,并初始化 Spring Environment
    • 支持自定义 RestTemplate,以满足特殊的安全需求。
官方文档
使用示例
  1. 创建 Config Server

    @SpringBootApplication
    @EnableConfigServer
    public class ConfigServer {
        public static void main(String[] args) {
            SpringApplication.run(ConfigServer.class, args);
        }
    }
    

    application.properties 中配置 Git 仓库地址:

    server.port: 8888
    spring.cloud.config.server.git.uri: file://${user.home}/config-repo
    
  2. 创建 Config Client
    在客户端项目中添加 bootstrap.yml

    spring:
      application:
        name: foo
      profiles:
        active: dev,mysql
      cloud:
        config:
          uri: http://localhost:8888
    

Spring Cloud Config 2.2.2 提供了强大的功能,用于集中化管理配置信息,支持多环境部署和动态刷新配置,同时确保配置的安全性和一致性。

Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system. With the Config Server you have a central place to manage external properties for applications across all environments. The concepts on both client and server map identically to the Spring Environment and PropertySource abstractions, so they fit very well with Spring applications, but can be used with any application running in any language. As an application moves through the deployment pipeline from dev to test and into production you can manage the configuration between those environments and be certain that applications have everything they need to run when they migrate. The default implementation of the server storage backend uses git so it easily supports labelled versions of configuration environments, as well as being accessible to a wide range of tooling for managing the content. It is easy to add alternative implementations and plug them in with Spring configuration.
Features

Spring Cloud Config Server features:

HTTP, resource-based API for external configuration (name-value pairs, or equivalent YAML content)

Encrypt and decrypt property values (symmetric or asymmetric)

Embeddable easily in a Spring Boot application using @EnableConfigServer

Config Client features (for Spring applications):

Bind to the Config Server and initialize Spring Environment with remote property sources

Encrypt and decrypt property values (symmetric or asymmetric)

Getting Started

As long as Spring Boot Actuator and Spring Config Client are on the classpath any Spring Boot application will try to contact a config server on http://localhost:8888, the default value of spring.cloud.config.uri. If you would like to change this default, you can set spring.cloud.config.uri in bootstrap.[yml | properties] or via system properties or environment variables.

@Configuration
@EnableAutoConfiguration
@RestController
public class Application {

@Value(“${config.name}”)
String name = “World”;

@RequestMapping(“/”)
public String home() {
return "Hello " + name;
}

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

}

The value of config.name in the sample (or any other values you bind to in the normal Spring Boot way) can come from local configuration or from the remote Config Server. The Config Server will take precedence by default. To see this look at the /env endpoint in the application and see the configServer property sources.

To run your own server use the spring-cloud-config-server dependency and @EnableConfigServer. If you set spring.config.name=configserver the app will run on port 8888 and serve data from a sample repository. You need a spring.cloud.config.server.git.uri to locate the configuration data for your own needs (by default it is the location of a git repository, and can be a local file:… URL).
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Bol5261

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值