Mybatis-config.xml中映射Mapper.xml文件遇到的錯誤及解決
Mybatis-config.xml中映射Mapper.xml文件遇到的錯誤
剛開始配置如下
<mappers>
<mapper resource="com.xieny.dao/UserMapper.xml" />
</mappers>報錯如下
Caused by: java.io.IOException: Could not find resource com.xieny.dao/UserMapper.xml

修改路徑格式后成功運行
<mappers>
<mapper resource="com/xieny/dao/UserMapper.xml" />
</mappers>Mapper與Mapper.xml 映射不到的解決
首先查看target中有沒有Mapper和Mapper.xml如果有仔細(xì)查看文件后綴是否正確,如xxx.xml,
如果沒有的話,試著用以下方式解決:
1.查看Mapper.xml中<Mapper namespace="路徑是否正確,是否正確指到Mapper">
2.查看Mapper.xml中<resultMap id="xxxx" type="此路徑是否正確指到bean">
3.在Spring boot啟動類加上@MapperScan("src/main/java/com/mapper")地址指向Mapper根目錄
4.在pom中添加掃描
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/**</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
spring boot實戰(zhàn)教程之shiro session過期時間詳解
SpringBoot項目中org.junit.jupiter.api.Test報錯問題及解決
SpringCloud中的@RefreshScope注解與使用場景方式
java學(xué)生信息管理系統(tǒng)設(shè)計

