IDEA配置使用Mybatis出现 “Could not find resource”
http://blog.csdn.net/haluoluo211/article/details/52370486
问题一:在Idea编辑其中配置使用Mybatis出现BuilderException问题,如下:
问题:在编译后的target文件夹下,发现只有mapper的class文件,而没有xml文件,将对应的xml文件放到这个文件夹下运行就不会出现下面的错误。说明出现这个错误的原因是maven编译时没有将xml文件放进去。
解决方法:在pom.xml中添加如下代码
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
问题二 mybatis读取配置文件报错:Could not find resource configuration.xml
码如下:
- Reader reader = null;
- try {
- reader = Resources.getResourceAsReader("configuration.xml");
- } catch (IOException e) {
- e.printStackTrace();
- }
执行之后报错:
- java.io.IOException: Could not find resource configuration.xml
- at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:89)
- at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:76)
- at org.apache.ibatis.io.Resources.getResourceAsReader(Resources.java:134)
说明:在项目src/main/resources目录下已经存在configuration.xml这个文件。
解决:You are using Maven, so you can leave off the src/main/resources
path altogether, as Conference.xml
will be found at the root of your classpath. This should work:
<mappers>
<mapper resource="Conference.xml" />
</mappers>
转载链接:http://stackoverflow.com/questions/19730026/mybatisibatis-xml-mapping-configuration