I am developing a Spring Boot [web] REST-style application with a ServletInitializer
(since it needs to be deployed to an existing Tomcat server). It has a @RestController
with a method that, when invoked, needs to write to a Redis pub-sub channel
. I have the Redis server running on localhost (default port, no password). The relevant part of the POM file has the required starter dependency:
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>
When I deploy the WAR and hit the endpoint http://localhost:8080/springBootApp/health
, I get this response:
{"status": "DOWN","diskSpace": {"status": "UP","total": 999324516352,"free": 691261681664,"threshold": 10485760 },"redis": {"status": "DOWN","error": "org.springframework.data.redis.RedisConnectionFailureException: java.net.SocketTimeoutException: Read timed out; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out" }}
I added the following to my Spring Boot application class:
@BeanJedisConnectionFactory jedisConnectionFactory() { return new JedisConnectionFactory();}@Beanpublic RedisTemplate<String, Object> redisTemplate() { RedisTemplate<String, Object> template = new RedisTemplate<String, Object>(); template.setConnectionFactory(jedisConnectionFactory()); return template;}
I also tried adding the following to my @RestController
before executing some test Redis code, but I get the same error as above in the stack trace:
@Autowiredprivate RedisTemplate<String, String> redisTemplate;
Edit (2017-05-09)My understanding is that Spring Boot Redis starter assumes the default values of spring.redis.host=localhost
and spring.redis.port=6379
, I still added the two to application.properties
, but that did not fill the gap.
Update (2017-05-10)I added an answer to this thread.