Result Maps collection already contains value for xxx.xxx.dao.BaseResultMap错误

本文介绍了在使用MyBatis逆向工程时遇到'Result Maps collection already contains value for...'错误的原因及解决方法。当误操作多生成Mapper配置后,启动项目会出现错误。解决方式是手动删除多余的Mapper配置,重启项目即可解决问题。作者强调对框架的深入理解和学习能有效避免类似bug,并分享了个人开发经验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言:

我们在实际开发项目中,有的时候会用到mybatis的逆向工程,这个东西在某种程度的确很省事,但有时候也会因此出现bug,这篇文章讲解下如何解决题目中的bug。

正文:

一、复现问题

1.1 点击maven插件时,一不小心多点了一下,看mapper.xml时又没注意,这时候逆向工程生成xxxxMapper.xml,xxx实体类,xxxMapper时并不会重复生成xxx实体类和xxxMapper的接口,只会在xml里多生成一遍增删改查语句

1.2 会在xml里多生成一份增删改查和<resultMap id="BaseResultMap''>,如下图的第4行和第104

1.3 这样你在启动项目时就出现下面的错误 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-04-26 20:34:27.567 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'adminLogController': Unsatisfied dependency expressed through field 'adminLogService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'AdminLogService': Unsatisfied dependency expressed through field 'adminLogDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'adminLogDao' defined in file [F:\tower\chinatower_main_service\target\classes\com\mainapp\chinatower_main_service\business\dao\AdminLogDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [F:\tower\chinatower_main_service\target\classes\mybatis\StudentMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.mainapp.chinatower_main_service.business.dao.StudentMapper.BaseResultMap
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1395)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.facto
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

开心的码字达

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值