mybatis 配置问题查找
2024-08-27 22:59:39
mybatis配置问题记录
org.apache.ibatis.binding.BindingException: Type interface com.xx.dao.UserDao(自己项目的文件) is not known to the MapperRegistry.
原因:MapperRegistry顾名思义 mapper没有注册 好比之前servlet学习的时候 每写一个servlet都要注册 此处也是一样 需要到你自己的mybatis核心配置文件中注册
解决办法
<mappers>
<mapper resource="xxx/xx/xx/xx.xml"/>
</mappers>
Cause: java.io.IOException: Could not find resource com/xx/dao/UserDao.xml(自己项目的xml文件)
原因:xx文件没有找到 但是一看项目中是有文件的 且路径也是对的 当文件存在什么都ok的情况下 一般就是配置问题了
maven约定大于配置 一般的文件都是放到resources文件夹下 现在放到java目录下了 可能存在导不出来等问题 解决办法
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
注意点
在Mybatis核心配置文件中注册Mappers时 如果使用<mappers><package name="xx.xxx.xxx"/></mappers>
或者<mappers><mapper class="xxx.xxx.xx.xxx"/></mappers>
这两种方式
dao
接口和xml
文件的名称必须一样
且必须放在同一个包中
最新文章
- Win10升级后回退后无法检测新版本的修复办法
- RabbitMQ高可用方案总结
- bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
- CSS中的::after ::before
- Vue基础理论
- NTP客户端的设置
- Asp.Net MVC过滤器小试牛刀
- JS的词法作用域
- 推荐一款非常好用的java反编译工具(转)
- java 制作QQ登录界面
- 原理Lambda表达式
- 简单开发Apple Watch的步骤
- SpringBoot图片上传(三)——调用文件上传项目的方法(同时启动两个项目)
- feign调用超时
- Beyond Compare 4 提示错误“这个授权密钥已被吊销”的解决办法
- [转]python3之日期和时间
- Android勒索软件研究报告
- ubuntu14.04 提示 卷 文件系统根目录 仅剩余xxx的硬盘空间
- 对象拷贝:jQuery extend
- Shell脚本 Hello World