Home > database >  Why is Spring trying to create a `redisReferenceResolver` bean?
Why is Spring trying to create a `redisReferenceResolver` bean?

Time:03-31

My project does use Redis but my unit test mocks it. However it doesn't mock it enough because I get this stack trace snippet:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisReferenceResolver': Cannot resolve reference to bean 'redisTemplate' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'redisTemplate' available
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:378)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110)

It is correct. I have carefully ensured there is no redisTemplate bean available because I don't want to run redis in my unit test. But I don't know why it is trying to create the redisReferenceResolver bean.

I've turned off autoconfiguration with this:

spring:
  profiles: RedisMock
  autoconfigure:
    exclude:
      - org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration

(my test has @ActiveProfiles({"WebMvcTest","RedisMock"}) in the top) I do have one class annotated with @RedisHash but I need that for my test. Anyone know what might be triggering the autoconfigure? Thanks

CodePudding user response:

redisReferenceResolver is defined by Spring Data’s support for Redis-based repositories. Setting spring.data.redis.repositories.enabled to false and ensuring that you haven’t used @EnableRedisRepositories anywhere in your app will disable it.

  • Related