'Inheritance in application properties in spring boot redis configuration

I have application.properties and application-dev.properties.

In my application.properties (single node instance)

spring.redis.host=127.0.0.1
spring.redis.port=6379

And in my application-dev.properties (since i have cluster set up in dev env)

spring.redis.cluster.nodes=10.212.41.20:6379, 10.292.40.291:6379

Now since spring.redis.host is not present in dev profile property file it is overriding from application.property and hence spring.redis.cluster.nodes is not taken into consideration.

How can i tell springboot to not override spring.redis.host when i am starting in dev profile



Solution 1:[1]

I would suggest to go with Redisson client (I do not know what client you use) and use something like this https://www.baeldung.com/redis-redisson

Essentially you create different config files per profile and can choose from many different type of topologies :

  • Single node
  • Master with slave nodes
  • Sentinel nodes
  • Clustered nodes
  • Replicated nodes

I've used it before and it's really clean as each environment is independent from the other (and in the application properties file you only define which file is the one for this env).

I hope it helped , although my suggestion is not what you exactly asked I wanted to share such an approach as it's clean in my opinion :)

Have a nice day :)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 XII