mybatis的报错看着我头疼,这个写给自己看。
类似于这种报错,我选中放到文本中来看,首先看前面的,在简化报错信息,比如下面的可以简化为:(见图下)
我知道有些人看英文头大,请忽视这些英文,把他(没错这一大段都是)看做一个一个符号分为:1、2、3、4,一个符号代表一个意思(不懂就百度翻译)。在逐步解决,具体见下图下的步骤:
- 提取前面报错信息为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
- 进一步将Errors分为一个个Error看:
- 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:
- 省略。。。
- 从3看出事userDao,其实并没有什么用,4给出了sqlSessionFactory,5给出了[mybatis-config.xml];,往后看事越来越准确详细,可知道事[mybatis-config.xml]出现了问题,实际上后面还有,一直报到映射文件UserMapper.xml,时间情况也是该文件出现错误。