admin管理员组文章数量:1794759
Consider defining a bean of type 'org.springframework.data.redis.core.HashOperations' 解决办法
问题描述:
使用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 &#039;org.springframework.data.redis.core.HashOperations&#039; 解决办法 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686552008a80989.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论