調試mybatis程序遇到的問題

對數據庫進行操作,有人偏愛Hibernate,有人偏愛ibatis(mybatis以前版本的名字)。Hibernate接觸過一些,但是,ibatis就沒有接觸了。這幾天心血來潮,想瞭解下ibatis。

網上一搜,才知道ibatis現在已經改名為mybatis了。我下載了最新的版本mybatis3.1.1。因為是第一次接觸,所以到網上搜了一個mybatis的實例,拷貝過來。誰知運行起來,老是出現下面的異常

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException: Content is not allowed in prolog.
at 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 t.MyBatisTest.main(MyBatisTest.java:18)
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException: Content is not allowed in prolog.
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:253)
at org.apache.ibatis.parsing.XPathParser.(XPathParser.java:122)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.(XMLConfigBuilder.java:71)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:76)
... 2 more
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1414)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1039)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:235)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:251)
... 5 more

網上一搜,發現原來是xml文件的第一行沒有拷貝完整,真是悲催,這點問題糾結了很久呢!

接下來相對比較順利,但是,很多地方mybatis似乎有bug,明明按照它自己的說明文檔做的,就是不正確。如mapper的注解版和mapper的xml版似乎有什麽衝突。

你可能感兴趣的:(开源,mybatis,ibatis,xml,ibatis,hibernate,exception,xml,thread)