Intellij IDEA中出现 Could not autowire. No beans of ‘***‘ type found. 的解决办法,@Autowired注入依赖时出现红色下划线

10 篇文章 0 订阅
7 篇文章 1 订阅

问题概述

这个是在项目开发过程中,使用Intellij IDEA工具时遇到的,在Service层中注入Dao层的Mapper类时,在Mapper类的变量出现红色下划线,但是项目又可以正常编译通过,且可以正常运行,将鼠标移动到Mapper上面的时候,提示:“ Could not autowire. No beans of 'UseNatureMapper' type found.  ”,如下图:

 

解决方案

两种解决方案:

第一种解决方案:

降低Spring 的@Autowired的检测级别,默认为Error,降级为Warning即可,点击 如下图:

第二种解决方案(推荐): 

在Dao层的Mapper文件中加入注解 “ @Repository ” ,将Mapper交由Spring来进行管理,这样也可以解决注入时找不到Bean的问题,如下图:

 

解决完成后,就不会再出现红色下滑行并提示找不到Beans的情况了,如下图:

关于这个@Autowired的强制性检测,我是将Intellij IDEA升级到2020或以上版本后,就遇到的这个问题。

 

 

 


 好了,关于 Intellij IDEA中出现 Could not autowire. No beans of ‘***‘ type found. 的解决办法,@Autowired注入依赖时出现红色下划线  就写到这儿了,如果还有什么疑问或遇到什么问题欢迎扫码提问,也可以给我留言哦,我会一一详细的解答的。 
歇后语:“ 共同学习,共同进步 ”,也希望大家多多关注CSND的IT社区。


作       者:华    仔
联系作者:who.seek.me@java98k.vip
来        源:CSDN (Chinese Software Developer Network)
原        文:https://blog.csdn.net/Hello_World_QWP/article/details/114923905#comments_15812156
版权声明:本文为博主原创文章,请在转载时务必注明博文出处!
  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Could not autowire. No beans of 'Integer' type found的错误提示意味着在自动装配找不到'Integer'类型的bean。这通常是由于没有在应用程序的上下文定义或配置'Integer'类型的bean所致。要解决此问题,可以采取以下步骤: 1. 检查配置文件:确保在应用程序的配置文件(如application.properties或application.yml)定义了正确的bean。例如,在Spring Boot应用程序,可以使用@Component或@Repository注释在对应的类上定义bean。 2. 检查包扫描:确保扫描到包含'Integer'类型bean的包。在Spring应用程序,默认情况下会扫描与主应用程序类相同的包及其子包。如果您的bean位于不同的包,可以通过@Configuration注释的类使用@ComponentScan指定要扫描的包。 3. 检查依赖注入:如果您正在使用@Autowired注释进行依赖注入,请确保@Autowired注释的字段或方法的类型与所需的'Integer'类型匹配。另外,也可以尝试使用@Qualifier注释指定要注入的特定bean。 4. 检查bean的定义:如果您手动定义bean,可以确保在配置文件(如XML配置文件)正确地定义了'Integer'类型的bean。确保bean的名称与@Autowired注释使用的名称匹配。 总结:Could not autowire. No beans of 'Integer' type found的错误提示表明在自动装配过程找不到'Integer'类型的bean。通过检查配置文件、包扫描、依赖注入和bean的定义,您可以解决此问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [IntelliJ Idea错误提示 Could not autowire. No beans of ‘‘ type found](https://blog.csdn.net/wangshuminjava/article/details/122616690)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Idea 解决 Could not autowire. No beans of 'xxxx' type found 的错误提示](https://download.csdn.net/download/weixin_38632624/12751965)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值