当我尝试从Spring Data Redis注入实现CrudRepository的存储库时,我得到NoSuchBeanDefinitionException .
引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有找到类型为[bluh.bluh.repository.XxxRepository]的限定bean用于依赖:预期至少有1个bean有资格作为此依赖项的autowire候选者 . 依赖注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}
但是有配置,它用 @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;
}
}
存储库界面如下所示:
import org.springframework.data.repository.CrudRepository;
public interface XxxRepository extends CrudRepository<String, String> { }
我已经经历了http://docs.spring.io/spring-data/redis/docs/current/reference/html/,'s nothing new for me. I wonder what did I miss and I'将会欣赏任何输入 .
我使用Spring Data Redis 1.7.2.RELEASE,Spring Boot 1.3.6.RELEASE
3 回答
有点迟到但对于其他任何有此问题的人:
我只是坐着把头发拉出来 . 下载了GIT示例并注意到该实体已使用@RedisHash(“hash_name_here”)注释:
现在它有连接问题,但我知道为什么:)
我遇到了同样的问题,并意识到这是一个版本问题 .
我使用的是spring-boot v1.3.8,并将spring-data-redis v1.7.5作为依赖项 . 当我尝试使用这些版本自动装配spring-data-redis存储库时,我收到了上述问题中发布的错误 .
我尝试升级到spring-boot v.1.4.2 . 这个版本的spring-boot附带了一个名为“spring-boot-starter-data-redis”的启动器,它可以降低spring-data-redis v1.7.5和jedis v2.8.2 . 我遵循文档中提供的相同配置,我终于开始工作了!
我猜测spring-boot v1.3.8和spring-data-redis v1.7.x存在一些兼容性问题 . 这有点得到证实,因为spring-boot 1.3.8带有一个名为spring-boot-starter-redis的启动器,它降低了spring-data-redis的v1.6.5 . 由于@EnableRedisRepositories注释仅包含在1.7中 . ,看起来需要升级才能使存储库功能正常工作 .
tl; dr尝试将spring boot升级到version.latest,并从spring-boot-starter-data-redis中获取spring-data-redis .
我有类似的问题 . 在我的情况下,版本不是问题,但注释需要一个明确的
basePackages
如下:@EnableRedisRepositories(basePackages = "my.base.pkg")