mybatis逆向工程遇到的坑

在做springboot与mybatis整合的时候,启动项目报错,具体错误如下

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
17:00:28.558 [RMI TCP Connection(5)-127.0.0.1] ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'roleController': Unsatisfied dependency expressed through field 'roleService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'roleServiceImpl': Unsatisfied dependency expressed through field 'roleMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'roleMapper' defined in file [D:\IDEA\workplace\yinzuo\target\yinzuo-0.0.1-SNAPSHOT\WEB-INF\classes\com\yy\yinzuo\dao\RoleMapper.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 [D:\IDEA\workplace\yinzuo\target\yinzuo-0.0.1-SNAPSHOT\WEB-INF\classes\mapper\TeacherMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [D:\IDEA\workplace\yinzuo\target\yinzuo-0.0.1-SNAPSHOT\WEB-INF\classes\mapper\TeacherMapper.xml]'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.yy.yinzuo.dao.TeacherMapper.BaseResultMap
	..........
	..........
	..........
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'roleServiceImpl': Unsatisfied dependency expressed through field 'roleMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'roleMapper' defined in file [D:\IDEA\workplace\yinzuo\target\yinzuo-0.0.1-SNAPSHOT\WEB-INF\classes\com\yy\yinzuo\dao\RoleMapper.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 [D:\IDEA\workplace\yinzuo\target\yinzuo-0.0.1-SNAPSHOT\WEB-INF\classes\mapper\TeacherMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [D:\IDEA\workplace\yinzuo\target\yinzuo-0.0.1-SNAPSHOT\WEB-INF\classes\mapper\TeacherMapper.xml]'.

一开始我一直觉得我的配置和注解的使用不正确,但是我检查了很多遍,发现都没有问题,百度了好多天也找不到答案,于是我干脆抛弃度娘自己找答案,顺着报错信息我发现了这个

nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [D:\IDEA\workplace\yinzuo\target\yinzuo-0.0.1-SNAPSHOT\WEB-INF\classes\mapper\TeacherMapper.xml]'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.yy.yinzuo.dao.TeacherMapper.BaseResultMap

然后我认真的去找这个Mapper映射文件,发现里面的有些字段是其它数据库的,不是我所要生成的表的字段。这让我认识到,逆向工程会扫描所有数据库来找到所要生成的表,如果两个数据库中的表名称一样,就会将这两张相同的表都生成连接在一起,这样子启动就会报错。所以逆向工程中一定要有这段配置

<property name="nullCatalogMeansCurrent" value="true"/>

具体位置如下
在这里插入图片描述
这让我深刻的意识到一定要好好看报错信息来找bug。
其实也不是什么大问题,但就是困扰了我好久,希望能帮到大家。

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值