Cannot resolve constructor ‘RedisCacheManager(org.springframework.data.redis.core.RedisTemplate)’

最近在學習spring boot+redis有關的問題,但是在學習的時候莫名的遇到了一個問題:Cannot resolve constructor 'RedisCacheManager(org.springframework.data.redis.core.RedisTemplate)。這就很難受了問題如下圖所示:

在這裏插入圖片描述
後來發現是版本問題,在springboot2.x中,RedisCacheManager已經沒有了單參數的構造方法。我上邊的方法是適用於spring 1x版本的。我的spring boot的版本是2x以上的版本。。。。。

直接改成下面管理緩存的放大就行了:

 // 管理緩存
    @Bean
    public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
        RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
                .entryTtl(Duration.ofHours(1)); // 設置緩存有效期一小時
        return RedisCacheManager
                .builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory))
                .cacheDefaults(redisCacheConfiguration).build();
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章