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>
特别容易大小写出错。