Type interface mapper.UserQueryMapper is already known to the MapperRegistry.

本文详细解析了在使用MyBatis框架时遇到的重复接口注册错误,并提供了具体的解决方案。错误源于同时使用资源方法加载映射文件和批量加载Mapper,导致UserQueryMapper接口重复注册。文章指导如何正确配置,避免此问题。

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

十二月 03, 2019 7:04:50 下午 org.springframework.context.support.AbstractApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis/SqlMapConfig.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.binding.BindingException: Type interface mapper.UserQueryMapper is already known to the MapperRegistry.

我这里引起的原因是:

<mappers>
<!--通过resource方法一次加载一个映射文件-->
        <mapper resource="sqlmap/UserMapper.xml"></mapper>
        <mapper resource="sqlmap/UserQueryMapper.xml"></mapper>
<!--批量加载Mapper-->
        <package name="mapper"/>
    </mappers>

处理方法是:

<mappers>
<!--通过resource方法一次加载一个映射文件-->
        <mapper resource="sqlmap/UserMapper.xml"></mapper>
        <mapper resource="sqlmap/UserQueryMapper.xml"></mapper>
<!--批量加载Mapper-->
        


   否则mappe文件会重复使用相关接口造成错误。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值