maven 加载不到xml文件
一、maven 加载不到xml文件
1、异常信息描述:
AbstractHandlerExceptionResolver.java:194 |org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver |Resolved exception caused by handler execution: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.guli.edu.mapper.CourseMapper.getCoursePublishVoById
问题分析:
dao层编译后只有class文件,没有mapper.xml,因为maven工程在默认情况下src/main/java目录下的所有资源文件是不发布到target目录下的,
解决方案:
1、在pom中配置如下节点
<!-- 项目打包时会将java目录中的*.xml文件也进行打包 --> <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources> </build>
重新打包项目会发现target目录下出现了xml文件夹
2、在Spring Boot配置文件中添加配置
#配置mapper xml文件的路径
mybatis-plus.mapper-locations=classpath:com/guli/eduservice/mapper/xml/*.xml
还有2种解决方案 一是直接将xml复制到target相应的目录下
2是把xml写到resources目录下
本文作者:KwFruit
本文链接:https://www.cnblogs.com/mangoubiubiu/p/13861442.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
分类:
疑难杂症
, 项目学习---尚硅谷-谷粒学院
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步