关于mybatis启动报Result Maps collection already contains value for ...的问题总结

错误重现

: 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 'userServiceImpl': Unsatisfied dependency expressed through field 'userMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [E:\study\apache-tomcat-7.0.73\webapps\tongxuelu\WEB-INF\classes\org\jxnd\tongxuelu\dao\UserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\study\apache-tomcat-7.0.73\webapps\tongxuelu\WEB-INF\classes\mapper\UserMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for org.jxnd.tongxuelu.dao.UserMapper.BaseResultMap

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)

at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
 

 

原因:,我更改了一个mapper方法的参数类型,

<select id="selectAllContractofPage" parameterType=" java.util.Map" resultMap="BaseResultOfPage">

结果多了一个空格!!!空格!!!

结果就找不到了。。。。

### 回答1: 该错误表示"多项目result maps collection already contains value for com.xy_asia.dic",意思是在多个项目的结果映射集合中已经包含了com.xy_asia.dic的值。 出现这个错误通常是因为在同一结果映射集合中重复定义了相同的映射。 要解决这个问题,我们可以按照以下步骤进行操作: 1. 确定出现错误的具体位置,通常是在mybatis的配置文件中的resultMap节点内发生。 2. 查找所有的resultMap节点,特别关注与com.xy_asia.dic相关的节点。 3. 检查是否存在相同的映射定义,例如是否有两个resultMap节点的id属性值都为com.xy_asia.dic。 4. 如果存在重复的映射定义,我们需要进行调整。可以通过删除重复的映射或者将它们合并为一个映射的方式来解决。 需要注意的是,在修改配置文件之前,最好备份原配置文件,以免发生意外情况导致配置文件无法使用。 完成以上步骤后,重新运行程序,这个错误应该就会被解决了。 希望以上解答能够帮助到您!如果还有其他问题,请随时提问。 ### 回答2: 多项目result maps collection already contains value for com.xy_asia.dic 出现的问题是由于多个项目中的结果映射集合中已经存在了 com.xy_asia.dic 的值。这个问题通常是由于在不同的项目中使用了相同的结果映射集合导致的。 解决这个问题的方法有几种: 1. 检查所有项目中的结果映射集合,确保没有重复的键值对。可以使用全局搜索来查找所有项目中是否存在相同的结果映射集合。 2. 如果项目中的结果映射集合被多次引用,可以考虑将其提取到一个公共的位置,例如一个共享的库文件或模块中。这样可以避免不同项目中的结果映射集合重复定义。 3. 如果需要在多个项目中使用相同的结果映射集合,可以将其拆分成多个部分,并在需要使用的项目中引入相应的部分。这样可以避免结果映射集合的重复定义,同时又可以满足各个项目的具体需求。 总之,解决多项目result maps collection already contains value for com.xy_asia.dic 的问题需要检查和管理各个项目中的结果映射集合,确保其唯一性和一致性。 ### 回答3: "多项目result maps collection already contains value for com.xy_asia.dic"这个错误是MyBatis框架在配置多个项目的result maps时发生的。这个错误表示在相同的result maps集合中已经存在一个key为com.xy_asia.dic的值。 造成这个错误的可能原因有两个: 1.配置文件中存在重复的result maps配置。这个错误可能是因为在多个项目的配置文件中都定义了名为com.xy_asia.dic的result maps,导致冲突发生。 2.不同项目之间配置文件的混淆。如果多个项目使用了相同的配置文件名或者配置文件所在位置,可能会导致项目之间的配置文件混淆,在解析时发生错误。 解决这个错误的方法是: 1.检查所有项目的配置文件,确保没有重复定义重名的result maps。可以使用编辑器的搜索功能,搜索并删除所有重复的result maps配置。 2.为每个项目设置不同的配置文件名或者配置文件存放位置,避免不同项目之间的配置文件混淆。 总结:出现"多项目result maps collection already contains value for com.xy_asia.dic"的错误是由于多个项目的配置文件中包含了重复的result maps配置或者不同项目之间的配置文件混淆所致。通过检查和清理重复配置,以及确保不同项目的配置文件不混淆,可以解决这个错误。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值