I have Spring Redis working using spring-data-redis
with all default configuration likes localhost
default port
and so on.
Now I am trying to make the same configuration by configuring it in application.properties
file. But I cannot figure out how should I create beans exactly that my property values are read.
Redis Configuration File
@EnableRedisHttpSession@Configurationpublic class SpringSessionRedisConfiguration {@BeanJedisConnectionFactory connectionFactory() { return new JedisConnectionFactory();}@Autowired@BeanRedisCacheManager redisCacheManager(final StringRedisTemplate stringRedisTemplate) { return new RedisCacheManager(stringRedisTemplate);}@Autowired@BeanStringRedisTemplate template(final RedisConnectionFactory connectionFactory) { return new StringRedisTemplate(connectionFactory);}}
Standard Parameters in application.properties
spring.redis.sentinel.master=themaster
spring.redis.sentinel.nodes=192.168.188.231:26379
spring.redis.password=12345
What I tried,
- I can possibly use
@PropertySource
and then inject@Value
and get the values. But I don't want to do that as those properties are not defined by me but are from Spring. - In this documentation Spring Redis Documentation, it only says that it can be configured using properties but doesn't show concrete example.
- I also went through Spring Data Redis API classes, and found that
RedisProperties
should help me, but still cannot figure out how exactly to tell Spring to read from properties file.