When I try to inject repository that implements CrudRepository from Spring Data Redis, I get NoSuchBeanDefinitionException.
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [bluh.bluh.repository.XxxRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
However configuration is there, it's annotated with @EnableRedisRepositories("bluh.bluh.repository")
@Configuration
@EnableRedisRepositories
public class ApplicationConfig {
@Bean
RedisConnectionFactory connectionFactory() {
return new JedisConnectionFactory();
}
@Bean
RedisTemplate<?, ?> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<byte[], byte[]> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
return template;
}
}
Repository interface looks like:
import org.springframework.data.repository.CrudRepository;
public interface XxxRepository extends CrudRepository<String, String> { }
I've been through http://docs.spring.io/spring-data/redis/docs/current/reference/html/ , there's nothing new for me. I wonder what did I miss and I'll appreciate any inputs.
I use Spring Data Redis 1.7.2.RELEASE, Spring Boot 1.3.6.RELEASE
I was having this same issue, and realized it was a version problem.
I was using spring-boot v1.3.8, and was pulling in spring-data-redis v1.7.5 as a dependency. I was getting the error posted in the question above when trying to autowire a spring-data-redis repository with these versions.
I tried upgrading to spring-boot v.1.4.2. This version of spring-boot comes with a starter called "spring-boot-starter-data-redis" that pulls down spring-data-redis v1.7.5 and jedis v2.8.2. I followed the same configuration as provided in the docs, and I finally got it to work!
I'm guessing there are some compatibility issues with spring-boot v1.3.8 and spring-data-redis v1.7.x. This was somewhat confirmed, by the fact that spring-boot 1.3.8 came with a starter called spring-boot-starter-redis that pulled down v1.6.5 of spring-data-redis. Since the @EnableRedisRepositories annotation was only included in 1.7.+, it looks like an upgrade is required to get the repositories functionality to work properly.
tl;dr try upgrading spring boot to version.latest, and pull in spring-data-redis from spring-boot-starter-data-redis.
Bit late but for anyone else having this issue:
I just sat pulling my hair out with this. Downloaded the GIT examples and noticed the entity was annotated with @RedisHash("hash_name_here"):
@RedisHash("MyDataThingies")
public class MyDataThingy{
@Id
public String id
}
Now it has connection issues but I know why :)
I had a similar problem. In my case the versions were not the problem but the annotation needed an explicit basePackages
like below:
@EnableRedisRepositories(basePackages = "my.base.pkg")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.