idea中配置使用mybatis出現問題BuilderException

來源:互聯網
上載者:User

在Idea編輯其中配置使用Mybatis出現BuilderException問題,問題描述如下:

2015-07-16 15:43:32,751 DEBUG [org.apache.ibatis.logging.LogFactory] - Logging initialized using 'org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl' adapter.2015-07-16 15:43:32,825 DEBUG [org.apache.ibatis.datasource.pooled.PooledDataSource] - PooledDataSource forcefully closed/removed all connections.2015-07-16 15:43:32,825 DEBUG [org.apache.ibatis.datasource.pooled.PooledDataSource] - PooledDataSource forcefully closed/removed all connections.2015-07-16 15:43:32,825 DEBUG [org.apache.ibatis.datasource.pooled.PooledDataSource] - PooledDataSource forcefully closed/removed all connections.2015-07-16 15:43:32,825 DEBUG [org.apache.ibatis.datasource.pooled.PooledDataSource] - PooledDataSource forcefully closed/removed all connections.Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession.### The error may exist in com/qunar/fresh/mybatistest/mapping/userMapper.xml### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/qunar/fresh/mybatistest/mapping/userMapper.xmlat org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:79)at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:63)at com.qunar.fresh.mybatistest.domain.Test.main(Test.java:20)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:606)at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/qunar/fresh/mybatistest/mapping/userMapper.xmlat org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:105)at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:88)at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:77)... 7 moreCaused by: java.io.IOException: Could not find resource com/qunar/fresh/mybatistest/mapping/userMapper.xmlat org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:104)at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:91)at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:309)at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:103)... 9 more

問題: 在編譯後的target檔案夾下,發現只有mapper的class檔案,而沒有xml檔案,將對應的xml檔案放到這個檔案夾下運行就不會出現下面的錯誤。說明出現這個錯誤的原因是maven編譯時間沒有將xml檔案放進去。

解決方案:在pom.xml中添加如下代碼

<build>...        <resources>            <resource>                <directory>src/main/java</directory>                <includes>                    <include>**/*.xml</include>                </includes>                <filtering>true</filtering>            </resource>        </resources>...</build>



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.