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