相信很多小伙伴都会遇到类似这样的错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactoryBean' defined in class path resource [Beans.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [SpecilinfoConfig.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/zhw/mapper/SpecilinfoMapper.xml
没关系在maven中,添加下面的节点就好了
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
即找不到SpecilinfoMapper.xml这个Mapper文件,仔细查看了目录设置,并没有错误,在网上找了半天,终于发现原因:idea不会编译src的java目录的xml文件
所以解决思路就是:将IDEA maven项目中src源代码下的xml等资源文件编译进classes文件夹
验证!
跑程序,报错!
加入上面的节点
再跑程序,成功!
把映射文件编译进去了!!