簡體   English   中英

Spring Data Redis NoSuchBeanDefinitionException:沒有類型的限定bean

[英]Spring Data Redis NoSuchBeanDefinitionException: No qualifying bean of type

當我嘗試從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/ ,對我來說沒什么新鮮的。 我想知道我錯過了什么,我會感激任何投入。

我使用Spring Data Redis 1.7.2.RELEASE,Spring Boot 1.3.6.RELEASE

我遇到了同樣的問題,並意識到這是一個版本問題。

我使用的是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。

有點遲到,但對於其他有這個問題的人:

我只是坐着把頭發拉出來。 下載了GIT示例並注意到該實體已使用@RedisHash(“hash_name_here”)注釋:

@RedisHash("MyDataThingies")
public class MyDataThingy{
    @Id
    public String id
}

現在它有連接問題,但我知道為什么:)

我遇到了類似的問題。 在我的情況下,版本不是問題,但注釋需要一個明確的basePackages如下所示:

@EnableRedisRepositories(basePackages = "my.base.pkg")

  • 使用springboot - 1.5.11和spring-data-redis-1.8.11

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM