mybatis错误——java.io.IOException: Could not find resource com/xxx/xxxMapper.xml
在说解决方案之前,先申明我的环境!我会用的开发工具是IDEA ,项目构建使用Maven!网上一些教程使用的Eclipse开发工具,项目是普通的java web项目,所以开发工具和构建项目不同就会存在一些出入(坑)!
原因:IDEA是不会编译src的java目录的xml文件,所以在Mybatis的配置文件中找不到xml文件!(也有可能是Maven构建项目的问题,网上教程很多项目是普通的Java web项目,所以可以放到src下面也能读取到)
方法1:
#不要把文件放到src下而是放到资源文件夹resources
方法2:
#在maven种的pom.xml配置文件中添加 <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> </resources> <resources> <resource> <directory>src/main/resources</directory> <includes>*.xml</includes> <includes>*.properties</includes> </resource> </resources> </build>