文章目錄
- 報錯連環案
- 案件一
- 案件二
- 案件三
- 案件四
- 案件總結
報錯連環案
案件一
- java.io.FileNotFoundException: d:axis.log (系統找不到指定的路徑。)
-
Exception in thread “main” org.apache.ibatis.exceptions.PersistenceException:
Error building SqlSession.
The error may exist in com/zyx/core/day1/dao
Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration.
Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.
Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允許有内容。
- 仔細檢查了一下,問題出現在了log4j日志的配置檔案中
- 這裡的
配置的是日志檔案路徑,我的盤中沒有D盤,同時路徑的格式也有問題。log4j.appender.LOGFILE.File
修改了之後,發現第一個路徑問題解決了,但是
Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允許有内容。
依然存在,上網搜了一下,說是大多數記事本工具(Emedit等)預設是以utf-8 BOM方式,會在檔案中加入BOM頭,導緻錯誤,然後我使用notpad++更改了之後還是不對。
點開日志檔案,發現編碼是 gbk?!而且也修改不了~
傳回頂部
案件二
又看了其他的報錯,
The error may exist in com/zyx/core/day1/dao
,這是MyBatis中的映射檔案配置路徑,寫錯了?
修改後:
好家夥,又報了新的錯!!!
傳回頂部
案件三
Exception in thread “main” org.apache.ibatis.binding.BindingException: Invalid bound statement
(not found): com.zyx.core.day1.dao.IUserDao.findAll
修改後,去掉方法後的括号 ():
傳回頂部
案件四
緊接着又報了錯:
Cause: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'com.zyx.core.day1.dao.IUserDao.findAll'. It's likely that neither a Result Type nor a Result Map was specified.
這個錯主要是因為我們,隻通過整個流程使用MyBatis去進行資料庫的操作,但是并沒有指定查到結果後的傳回類型,在代碼中我們是要查詢所有,同時建立了實體類,是以這裡我們最終的傳回類型就應該是實體類類型;通過resultType屬性設定傳回類型的全路徑類。
最終運作結果:
案件總結
整理一下所有報錯,wy~
- 1.
配置日志路徑的時候要注意本地存在~java.io.FileNotFoundException: d:axis.log (系統找不到指定的路徑。)
- 2.
很有可能是UTF-8 BOM 格式的問題,顯然這裡我的不是~,但值得注意!!!Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允許有内容。
- 3.
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: Error building SqlSession.The error may exist in com/zyx/core/day1/dao
Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration.
這個錯是由于映射配置檔案路徑沒寫全導緻後面解析配置檔案建立SqlSessionFactory工廠失敗,注意路徑要一直寫到具體的配置檔案。Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.
- 4.
這個錯是由于在配置具體映射檔案的時候,配置增強dao層的方法時多添加了() 引起的,注意不需要!!!Exception in thread “main” org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.zyx.core.day1.dao.IUserDao.findAll
- 5.
這個錯主要是因為我們,隻通過整個流程使用MyBatis去進行資料庫的操作,但是并沒有指定查到結果後的傳回類型,在代碼中我們是要查詢所有,同時建立了實體類,是以這裡我們最終的傳回類型就應該是實體類類型;通過resultType屬性設定傳回類型的全路徑類。Cause: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'com.zyx.core.day1.dao.IUserDao.findAll'. It's likely that neither a Result Type nor a Result Map was specified.