mybatis配置运行报出Caused by: org.apache.ibatis.binding.BindingException:相关错误解决或者空指针异常

问题一报出Type interface com.example.springboot.mappers.AyUserMapper is already known to the MapperRegistry.

Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.binding.BindingException: Type interface com.example.springboot.mappers.AyUserMapper is already known to the MapperRegistry.

	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
	
	报出Type interface com.example.springboot.mappers.AyUserMapper is already known to the MapperRegistry.
	意思是说MapperRegistry. mapper注册表应经知道这个mapper已经注册
	那已经注册为啥会报错,我搜索很多相关就两个解决方案
	
	方案一
	看mybatis-config配置中和对应mapper.xml文件中命名空间namespace是否一样
	<mappers>
        <mapper resource="com/example/springboot/mappers/AyUserMapper.xml"></mapper>
    </mappers>
    UserInfoMapper.xml
    <mapper namespace="com.example.springboot.mappers.AyUserMapper"></mapper>
    我使用idea   namespace
    修改成<mapper namespace="com/example/springboot/mappers/AyUserMapper"></mapper>
    就成功运行。
	

问题二 运行直接报出空指针异常

问题可能出现在src/mian/java相关路径下创建mappper.xml文件
在这里插入图片描述
程序运行时候mybatis-scan 并不会扫描java包下的xml文件打包亦不会打包
解决方案(加入下面代码让程序进行加载扫描java包下xml文件)

     <build>    
         <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
    </build>

方案二就是将xml文件创建在resource目录下然后在mybatis-config配置下改成(可能这个方法不一定行)

<mappers>
        <mapper resource="mappers/AyUserMapper.xml"></mapper>
    </mappers>

问题三mybatis mapper接口报出org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.springboot.mappers.AyUserMapper.findNameById

解决方案
请参照解决方案内容很详尽

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值