mybatis逆向工程生成后,使用注入报错的问题 Exception encountered during context initialization - cancelling refresh at

Exception encountered during context initialization - cancelling refresh attempt: 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 mapping resource: 'file [D:\javaexercise\furn-ssm\target\classes\mapper\FurnMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [D:\javaexercise\furn-ssm\target\classes\mapper\FurnMapper.xml]'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.ymt.furn.dao.FurnMapper.BaseResultMap

出现这样的报错,你往下拉还可以看到

ailed to parse mapping resource: 'file [D:\javaexercise\furn-ssm\target\classes\mapper\FurnMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [D:\javaexercise\furn-ssm\target\classes\mapper\FurnMapper.xml]'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for

xml信息重复或具体是 Result Maps 集合中已经包含了一个值为 com.ymt.furn.dao.FurnMapper.BaseResultMap 的元素,这通常意味着 BaseResultMap 在 XML 文件中被重复定义了,或者在其他地方(可能是同一个 XML 文件或其他 Mapper XML 文件)被错误地引用了。

========原因是=========

一.你用逆向工程生成的xml文件内容重复导致的报错 正常生成的*.xml文件都是200多行,如果有500百行以上就是重复生成了,如果你一个个去对应的查id,可以查到很多重复的,你可以先去删除对应的xml文件后重新生成,要在你的逆向工程这段话中

<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                connectionURL="jdbc:mysql://127.0.0.1:3306/furn_ssm?useSSL=true&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;rewriteBatchedStatements=true&amp;autoCommit=true"
                userId="xxx"
                password="xxx">
</jdbcConnection>

二.加入这段话<property name="nullCatalogMeansCurrent" value="true" />防止重复

然后重新生成运行就可以了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值