问题一报出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
解决方案
请参照解决方案内容很详尽