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

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

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

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

 

  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往错误源推算。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

长臂人猿

客官们众筹请博主喝杯奶茶吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值