搭建简单的mybatis环境时,mapper以及对应的xml文件放在同一包下,但是启动时却报错,找不到对应的xml,报错信息如下:
The error may exist in itcast/mapper/UserMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource itcast/mapper/UserMapper.xml
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64) at itcast.HelloMybatis.main(HelloMybatis.java:21)
报错信息很明显,就是找不到mapper对应的xml文件,解决方法如下,在pom.xml文件中添加如下配置:
<build>
<resources>
<!-- resources文件 -->
<resource>
<directory>src/main/java</directory>
<!-- 引入映射文件 -->
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>