Consider defining a bean of type 'org.springframework.data.redis.core.HashOperations' 解决办法

编程知识 更新时间:2023-05-02 05:34:15

问题描述:

使用Spring Boot最新版Spring Boot-2.0.3整合Redis,在启动项目时,遇到的一个bug,异常信息如下:

Description:

Field hashOperations in com.iap.springboot.service.IRedisService required a bean of type 'org.springframework.data.redis.core.HashOperations' that could not be found.


Action:

Consider defining a bean of type 'org.springframework.data.redis.core.HashOperations' in your configuration.

Disconnected from the target VM, address: '127.0.0.1:60388', transport: 'socket'

Process finished with exit code 1

该bug导致项目一直无法正常启动,说在IRedisService接口中缺少 hashOperations 的Bean,并建议定义一个Bean 类型的 HashOperations,如下图:


解决办法:

根据错误信息提示,在Redis配置文件中添加 HashOperations Bean类型的组件,并在IRedisService接口中整一个HashOperations 的在字段就可以了,

在Redis文件中,注入Bean组件 HashOperations ,加入内容如下:

    @Bean
    public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {
        return redisTemplate.opsForHash();
    }

如下图:

在IRedisService接口中整一个字段,进行调用;
内容如下:

    @Resource
    private HashOperations<String, String, T> hashOperations;

注意:一定要使用@Resource注解,而不能使用@Autowired注解哟!!!
如下图:

配置添加完成后,项目就可以成功启动了,如下图:


好了,关于 Consider defining a bean of type ‘org.springframework.data.redis.core.HashOperations’ 解决办法 就写到这儿了,如果还有什么疑问或遇到什么问题欢迎扫码提问,也可以给我留言哦,我会一一详细的解答的。
歇后语:“ 共同学习,共同进步 ”,也希望大家多多关注CSND的IT社区。

更多推荐

Consider defining a bean of type 'org.springframework.data.redis.core.HashO

本文发布于:2023-04-26 07:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/7607c0121a1801813cb3e9359a97dfaf.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:解决办法   type   org   defining   bean

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 104670文章数
  • 26217阅读数
  • 0评论数