按照网上教程搭建mybatis开发环境,我的本地目录如下:
其中测试的映射文件位置在com.yd.mapper.UserMapper.xml中
内容如下
select * from user where id = #{id}
MyBatis的配置文件如下
报错信息如下:
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/yd/mapper/UserMapper.xml at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:122) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:99) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:78) ... 2 more Caused by: java.io.IOException: Could not find resource com/yd/mapper/UserMapper.xml at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:114) at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:100) at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:377) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:120) ... 4 more
原因是视频教程是用Eclipse,而我本地用的是idea,idea不会编译src的java目录的xml文件
解决:在pom.xml中添加build
src/main/java com/yd/mapper/*.xml
再次执行,已不报错
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)