I have this configuration for my pub/sub implementation:
@Beanpublic RedisMessageListenerContainer container(LettuceConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) { RedisMessageListenerContainer container = new RedisMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.addMessageListener(listenerAdapter, new ChannelTopic(publishChannel)); return container;}@Beanpublic MessageListenerAdapter listenerAdapter(RedisReceiver receiver) { return new MessageListenerAdapter(receiver, "receiveMessage");}@Beanpublic StringRedisTemplate template(LettuceConnectionFactory connectionFactory) { return new StringRedisTemplate(connectionFactory);}
This code worked fine until I updated to Spring-Boot 2.7 (previously 2.6.7).Now this code throws the following error on startup, when my Redis is not running:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'container'; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to localhost/:6379
("container" is the Bean at the top in my code snippet)
Where or how can I configure that it catches the thrown exception on startup and just retries it again until the connection to Redis is available?