此版本仍在开发中,目前尚不稳定。如需最新稳定版本,请使用 Spring Cloud Config 5.0.1spring-doc.cadn.net.cn

Redis 后端

Spring Cloud Config Server 支持 Redis 作为配置属性的后端存储。您可以通过添加对 Spring Data Redis 的依赖来启用此功能。spring-doc.cadn.net.cn

pom.xml
<dependencies>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-data-redis</artifactId>
	</dependency>
</dependencies>

以下配置使用 Spring Data RedisTemplate 访问 Redis。我们可使用 spring.redis.* 属性来覆盖默认的连接设置。spring-doc.cadn.net.cn

spring:
  profiles:
    active: redis
  redis:
    host: redis
    port: 16379

属性应作为字段存储在哈希表中。哈希表的名称应与 spring.application.name 属性相同,或为 spring.application.namespring.profiles.active[n] 的组合。spring-doc.cadn.net.cn

HMSET sample-app server.port "8100" sample.topic.name "test" test.property1 "property1"

在运行上述命令后,哈希中应包含以下键及其对应的值:spring-doc.cadn.net.cn

HGETALL sample-app
{
  "server.port": "8100",
  "sample.topic.name": "test",
  "test.property1": "property1"
}
当未指定配置文件时,将使用 default