Error message

12:18:07.526 [main] WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redis' defined in class path resource [com/org/api/common/health/redis/RedisHealthCheckAutoConfiguration.class]: Unsatisfied dependency expressed through method 'redis' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/JedisConnectionConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.jedis.JedisConnectionFactory]: Factory method 'redisConnectionFactory' threw exception; nested exception is java.lang.NoSuchMethodError: 'void org.springframework.data.redis.connection.RedisSentinelConfiguration.setUsername(java.lang.String)'

...

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.boot.autoconfigure.data.redis.RedisConnectionConfiguration.getSentinelConfig(RedisConnectionConfiguration.java:85)

The following method did not exist:

    'void org.springframework.data.redis.connection.RedisSentinelConfiguration.setUsername(java.lang.String)'

The method's class, org.springframework.data.redis.connection.RedisSentinelConfiguration, is available from the following locations:

    jar:file:/Users/mymac/.m2/repository/org/springframework/data/spring-data-redis/2.2.4.RELEASE/spring-data-redis-2.2.4.RELEASE.jar!/org/springframework/data/redis/connection/RedisSentinelConfiguration.class

The class hierarchy was loaded from the following locations:

    org.springframework.data.redis.connection.RedisSentinelConfiguration: file:/Users/mymac/.m2/repository/org/springframework/data/spring-data-redis/2.2.4.RELEASE/spring-data-redis-2.2.4.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.redis.connection.RedisSentinelConfiguration

My understanding is that there is no compatible version available of org.springframework.data.redis.connection.RedisSentinelConfiguration because

https://github.com/spring-projects/spring-boot/pull/29661 added https://github.com/spring-projects/spring-boot/blob/7dd8dfc19741d149fe2a93ccd8147c505d8181b1/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisConnectionConfiguration.java#L98

which calls RedisSentinelConfiguration.setUsername() resulting in a NoSuchMethodError seen above. setUsername was added in https://github.com/spring-projects/spring-data-redis/issues/2218 which won't be released until 2.7.0.

Versions:

spring-boot version: 2.5.13
spring-boot-autoconfigure version: 2.5.13
spring-redis-data version: 2.2.4.RELEASE

application.yaml contains

spring:
  redis:
    sentinel:
      master: mymaster
      nodes: redis-sentinel:26379

Comment From: wilkinsona

setUsername was added to RedisSentinelConfiguration in Spring Data Redis 2.4.

To ensure that you are using compatible versions, please use Spring Boot's dependency management or refer to the reference documentation's dependency versions appendix. Spring Boot 2.5.13 uses Spring Data Redis 2.5.11 by default.

Comment From: GSvensk

Thank you for the quick response!