|
此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Cloud Config 4.1.4! |
Redis 后端
Spring Cloud Config Server 支持将 Redis 作为配置属性的后端。 您可以通过向 Spring Data Redis 添加依赖项来启用此功能。
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies>
以下配置使用 Spring DataRedisTemplate以访问 Redis。我们可以使用spring.redis.*properties 覆盖默认连接设置。
spring:
profiles:
active: redis
redis:
host: redis
port: 16379
属性应作为字段存储在哈希中。hash 的名称应与spring.application.name属性或连词spring.application.name和spring.profiles.active[n].
HMSET sample-app server.port "8100" sample.topic.name "test" test.property1 "property1"
运行上方可见的命令后,哈希应包含以下键和值:
HGETALL sample-app
{
"server.port": "8100",
"sample.topic.name": "test",
"test.property1": "property1"
}
未指定配置文件时default将被使用。 |