开发中的各种问题记录之Mybatis的坑Result Maps collection already contains value for com.bs.dao.UserMapper.BaseResu

首先说一下出现的问题:

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'informationController': Unsatisfied dependency expressed through field 'informationDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'informationDao' defined in file [F:\JavaEE\employmentinformationsystem\target\classes\com\bs\dao\InformationDao.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 URL [file:/F:/JavaEE/employmentinformationsystem/target/classes/spring/springmvc.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [F:\JavaEE\employmentinformationsystem\target\classes\mapper\UserMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [F:\JavaEE\employmentinformationsystem\target\classes\mapper\UserMapper.xml]'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.bs.dao.UserMapper.BaseResultMap
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)

这个就是问题,其余的内容也没有必要多粘,然后就说明一下是问题的原因是:

我的springmvc.xml中有这样的一句配置:

开发中的各种问题记录之Mybatis的坑Result Maps collection already contains value for com.bs.dao.UserMapper.BaseResu

其作用就是将该目录下所有符合名称规范的mapper问价都扫描到容器中,然后进行相应的接口和标签的映射。

那么这样按照我的目录结构其扫描结果就是:

开发中的各种问题记录之Mybatis的坑Result Maps collection already contains value for com.bs.dao.UserMapper.BaseResu

然后再看一下我的两个配置文件中的BaseResultMap的写法:

UserMapper.xml

开发中的各种问题记录之Mybatis的坑Result Maps collection already contains value for com.bs.dao.UserMapper.BaseResu

InformationMapper.xml

开发中的各种问题记录之Mybatis的坑Result Maps collection already contains value for com.bs.dao.UserMapper.BaseResu

对,问题就出在这里,出现的错也是因为已经有了BaseResultMap这个map,就不能再有了,所以把其中的一个换掉,就好了,这个问题很。。(口吐芬芳)。。

 

 

希望有帮助,欢迎指点。