SPRINGBOOT-4-部分报错排查逻辑

1.org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.imooc.dao.AreaDao.queryAreaTest

该报错的原因是mybatis-config.xml中缺少<mapper>配置

<mappers>
        <mapper resource="mybatis/mapper/xgwTestDao.xml"/>
</mappers>

但教程中无该配置,不会报错,原因不明。

 

2. SQLSessionFactory 无法创建Bean问题(调整过程中可能会有多种报错)

第一种:

 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'AreaServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.imooc.dao.AreaDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'AreaService' defined in file [/Users/dd/Desktop/IntellijIDEA/network-report/dd-start/target/classes/com/imooc/service/AreaService.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource 

第二种:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'AreaServiceImpl': Unsatisfied dependency expressed through field 'AreaDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.imooc.dao.AreaDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

第三种:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'AreaServiceImpl': Unsatisfied dependency expressed through field 'AreaDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.imooc.dao.AreaDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'AreaService' defined in file [/Users/dd/Desktop/IntellijIDEA/network-report/dd-service/target/classes/com/imooc/service/AreaService.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/imooc/datasource/SessionFactoryConfiguration.class]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException

最早的报错形式其实是AreaDao这个Bean无法创建,但其根本原因是SQLSessionFactory创建不成功。

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.imooc.dao.AreaDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}

最根本的原因是因为使用了XML文件配置,如果文件配置中缺失文件或者文件名不对或者其他问题,统一都会报SQLSessionFactory相关的错误

已知的需要保持一致的地方:AreaDao.java和AreaDao.xml 和Mybastis-config.xml中的<mapper>

特别容易大小写出错。

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值