spring.redis.* should be spring.data.redis.* in spring boot 3
spring cloud bindings is failing in spring boot 3 due to pointing against old value
@mhoshi-vm
In the meantime, you can use this:
Import spring cloud bindings in your app compile scope
e.g. gradle:
compileOnly("org.springframework.cloud:spring-cloud-bindings:1.10.0")
Please note this is in repo.spring.io, not maven-central.
Add the Boot3RedisPropertiesProcessor
public class Boot3RedisPropertiesProcessor implements BindingsPropertiesProcessor {
public static final String TYPE = "redis";
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!shouldApply(environment)) {
return;
}
bindings.filterBindings(TYPE).forEach(binding -> {
var mapper = new BindingPropertiesMapper(binding.getSecret(), properties);
mapper.map("client-name", "spring.data.redis.client-name");
mapper.map("cluster.max-redirects", "spring.data.redis.cluster.max-redirects");
mapper.map("cluster.nodes", "spring.data.redis.cluster.nodes");
mapper.map("database", "spring.data.redis.database");
mapper.map("host", "spring.data.redis.host");
mapper.map("password", "spring.data.redis.password");
mapper.map("port", "spring.data.redis.port");
mapper.map("sentinel.master", "spring.data.redis.sentinel.master");
mapper.map("sentinel.nodes", "spring.data.redis.sentinel.nodes");
mapper.map("ssl", "spring.data.redis.ssl");
mapper.map("url", "spring.data.redis.url");
});
}
static class BindingPropertiesMapper {
private final Map<String, String> secret;
private final Map<String, Object> properties;
private final PropertyMapper mapper;
public BindingPropertiesMapper(Map<String, String> secret, Map<String, Object> properties) {
this.secret = secret;
this.properties = properties;
this.mapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
}
public void map(String from, String to) {
mapper.from(secret.get(from)).to(value -> this.properties.put(to, value));
}
}
private static boolean shouldApply(Environment environment) {
return environment.getProperty(String.format("org.springframework.cloud.bindings.boot.%s.enable", TYPE),
Boolean.class, true);
}
}
Register the processor
In src/main/resources/META-INF/spring.factories add:
org.springframework.cloud.bindings.boot.BindingsPropertiesProcessor=YOUR.PACKAGE.PATH.Boot3RedisPropertiesProcessor
Here's an other workaround:
spring:
data:
redis:
# Workaround for https://github.com/spring-cloud/spring-cloud-bindings/issues/87:
host: ${spring.redis.host}
password: ${spring.redis.password}
Related: #89
Here's an other workaround:
spring: data: redis: # Workaround for https://github.com/spring-cloud/spring-cloud-bindings/issues/87: host: ${spring.redis.host} password: ${spring.redis.password}
Note: the above workaround will break when gh-94 gets merged ; the custom BindingsPropertiesProcessor will not break.
hello, latest work is in https://github.com/spring-cloud/spring-cloud-bindings/pull/94 and should be merged soon; stay tuned! as @Kehrlann mentioned in https://github.com/spring-cloud/spring-cloud-bindings/issues/87#issuecomment-1451861110
https://github.com/spring-cloud/spring-cloud-bindings/pull/94 is closed, but superseded by #99. Does that mean this issue is resolved in v2.0.1?