mybatis的报错看着我头疼,这个写给自己看。

类似于这种报错,我选中放到文本中来看,首先看前面的,在简化报错信息,比如下面的可以简化为:(见图下)

我知道有些人看英文头大,请忽视这些英文,把他(没错这一大段都是)看做一个一个符号分为:1、2、3、4,一个符号代表一个意思(不懂就百度翻译)。在逐步解决,具体见下图下的步骤:

如何查看Mybatis的报错(方法)

 

  1. 提取前面报错信息为errors:                  Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in file [D:\JAVA\JAVA2\Mybatis\target\classes\dao\UserDao.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis-config.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'mybatis/UserMapper.xml'. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for dao.UserDao.selectUserById. please check mybatis/UserMapper.xml and mybatis/UserMapper.xml
  2. 进一步将Errors分为一个个Error看:  
  3. Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userDao'; nested exception is org.springframework.beans.factory.BeanCreationException: 
  4. Error creating bean with name 'userDao' defined in file [D:\JAVA\JAVA2\Mybatis\target\classes\dao\UserDao.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException:
  5. Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis-config.xml]; nested exception is org.apache.ibatis.builder.BuilderException: 
  6. 省略。。。
  7. 从3看出事userDao,其实并没有什么用,4给出了sqlSessionFactory,5给出了[mybatis-config.xml];,往后看事越来越准确详细,可知道事[mybatis-config.xml]出现了问题,实际上后面还有,一直报到映射文件UserMapper.xml,时间情况也是该文件出现错误。

总结:错误分为父-》子-》孙,但建议将错误整合出来,一个个error往错误源推算。

相关文章:

  • 2022-01-21
  • 2022-12-23
  • 2022-12-23
  • 2022-02-24
  • 2021-11-12
  • 2022-01-04
猜你喜欢
  • 2023-04-06
  • 2021-12-19
  • 2022-02-13
  • 2021-04-02
  • 2022-12-23
  • 2021-06-24
相关资源
相似解决方案