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如果有仔细查看文件后缀是否正确,如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>总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
spring boot实战教程之shiro session过期时间详解
这篇文章主要给大家介绍了关于spring boot实战教程之shiro session过期时间的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起看看吧。2017-10-10
SpringBoot项目中org.junit.jupiter.api.Test报错问题及解决
这篇文章主要介绍了SpringBoot项目中org.junit.jupiter.api.Test报错问题及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2023-11-11
SpringCloud中的@RefreshScope注解与使用场景方式
SpringCloud中的@RefreshScope注解用于动态刷新Bean配置,解决外部配置变化时的问题,避免重启应用,通过本文的详细介绍,希望读者能够更好地掌握@RefreshScope的使用技巧,在实际项目中灵活应用,提升微服务应用的动态配置管理能力2024-12-12


最新评论