Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spring.redis.* should be spring.data.redis.* in spring boot 3 #87

Open
mhoshi-vm opened this issue Dec 16, 2022 · 7 comments
Open

spring.redis.* should be spring.data.redis.* in spring boot 3 #87

mhoshi-vm opened this issue Dec 16, 2022 · 7 comments

Comments

@mhoshi-vm
Copy link

spring cloud bindings is failing in spring boot 3 due to pointing against old value

@Kehrlann
Copy link
Contributor

@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

@alexandreroman
Copy link

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}

@Kehrlann
Copy link
Contributor

Related: #89

@Kehrlann
Copy link
Contributor

Kehrlann commented Mar 2, 2023

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.

@karolpawlak
Copy link

@anthonydahanne
Copy link
Collaborator

anthonydahanne commented Mar 7, 2023

hello, latest work is in #94 and should be merged soon; stay tuned! as @Kehrlann mentioned in #87 (comment)

@mamachanko
Copy link
Contributor

mamachanko commented Jul 28, 2023

#94 is closed, but superseded by #99. Does that mean this issue is resolved in v2.0.1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants