出现No qualifying bean of type [com.*.*.dao.InfoDao] found for :错误!

本文详细解析了在使用SpringMVC、MyBatis框架时,多级目录配置不当导致Tomcat启动时报错的问题,并提供了解决方案。通过在applicationContext.xml文件中增加配置,解决了找不到DAO类的错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、问题:启动Tomcat时报错!
主要错误代码如下

No qualifying bean of type [com.*.*.*.*.*.dao.InfoDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)}

在这段代码之前还有错误代码:

WARN  o.s.w.c.s.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt

2、出现错误的环境:Spring MVC + MyBatis框架下,涉及有control层、service层、dao层。
3、问题分析:一开始以为是由于control层使用@Resource出现的异常,但是经过逐层排查,错误的根源是在service层中的注解处引发的,从网上查找相关资料说是:找不到dao类
注:我的注解路径都没有问题,但是还是出现错误。
4、我的错误原因:在工程目录下创建了多级目录,而对applicationContext.xml文件的

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

标签中没有进行“添加“多级的配置(原来的该配置文件中只有两级目录,需要再添加一级)
5、问题解决方法:在工程中有个applicationContext.xml文件,打开后,如下图:
打开applicationContext.xml文件
注:(1)找到bean标签,一开始的设置只有前两个,而我的解决方法就是在后面加入蓝色框中的内容,即可解决上述问题。
(2)上面第3点的“注”中说过:我的错误不是因为注解路径的原因引起的,而是因为配置文件中设置的自动扫描目录为2级引起的,而我要运行的代码是3级目录,所以需要再加一级。
(3)综合网上大多数引起这种错误的原因,我觉得主要是在配置文件中(我的是applicationContext.xml)去进行修改,特别注意一下
6、结语
上面所述只是引起这种错误的原因之一,在此分享。

感谢阅读,如果有些语句不通顺或者逻辑不够清晰,请大家见谅!如果有问题,大家也可以提提改善的意见!(^_−)☆

引用:出现No qualifying bean of type [com...dao.InfoDao] found for :错误 链2:Error creating bean with name ‘userServiceImpl’: Injection of autowired dependencies failed 链3:SPRING MVC 配置报错: ERROR CREATING BEAN WITH NAME ‘USERCONTROLLER’: INJECTION OF RESOURCE DEPENDENCIES 链4:解决Error creating bean with name XXX: Injection of resource dependencies failed 。 引用:Error creating bean with name 'projectReservePoolController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xuci.apply.service.IProjectReservePoolService' available: expected at least 1 bean which qualifies as autowire candidate. 。 引用:报错: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookDao' defined in file [D:\code\ideaProjectsCode\spring\ssm\target\ssm-1.0-SNAPSHOT\WEB-INF\classes\com\nxg\dao\BookDao.class]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.apache.ibatis.session.defaults.DefaultSqlSessionFactory' to required type 'org.mybatis.spring.SqlSessionTemplate' for property 'sqlSessionTemplate'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'org.apache.ibatis.session.defaults.DefaultSqlSessionFactory' to required type 'org.mybatis.spring.SqlSessionTemplate' for property 'sqlSessionTemplate': 。 根据引用和引用的错误信息,"Error creating bean with name 'carController': Injection of resource dependencies failed"表示在创建名为'carController'的bean时,注入资源的依赖项失败。这种错误通常出现在Spring的依赖注入中,可能是由于找不到或无法匹配所需类型的bean而导致的。在这种情况下,可能需要检查bean的配置和依赖项的注入方式,确保正确配置和匹配。另外,还需要检查所需类型的bean是否已经正确定义和可用。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [ssm之Error creating bean with name ‘bookServiceImpl‘: Injection of resource dependencies failed;](https://blog.csdn.net/nxg0916/article/details/126235159)[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* [springboot:Error creating bean with name ‘XXXController‘: Injection of resource dependencies failed](https://blog.csdn.net/qq_43790218/article/details/127878908)[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 ]
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值