mybatis入门常见错误
1.Exception in thread "main" java.io.IOException: Could not find resource config2.xml
需要去Reader reader=Resources.getResourceAsReader("config2.xml");代碼處看下,是否和src下面的配置文件名稱一樣,如果不一樣,澤會報沒有發現資源文件的錯誤;
2.White spaces are required after keyword PUBLIC in DOCTYPE decl,原因是<!DOCTYPE configuration PUBLIC"-//mybatis.org//DTD Config 3.0//EN"
?? ?"http://mybatis.org/dtd/mybatis-3-config.dtd">,public后面應該加空格;
3.Element type "enviroments" must be declared.或Element type "enviroment" must be declared.,Attribute "resourse" must be declared for element type "mapper".等type需要定義的錯誤,則是標簽出問題了,需要檢查xml配置文件;
4.The content of element type "transactionManager" must match "(property)*".,錯誤是<transactionManager type="JDBC"/>,標簽用完就結束,不要包含property.
5.Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Dept'.? Cause: java.lang.ClassNotFoundException: Cannot find class: Dept,,原因是<select id="selectOne" parameterType="int" resultType="Dept">,此處的返回類型出問題了!!!,需要返回bean包下的實體類。
綜上所述,針對開始學習配置文件的同學們來說,寫的時候,要仔細再仔細!!!注意大小寫 空格 單引號 全交 半角等等問題!!!
6.### Error opening session.? Cause: java.lang.NullPointerException
### Cause: java.lang.NullPointerException,原因是配置環境問題
<environments default="development">
?? ??? ??? ?<environment id="developmet">,id和default要一致;
?
總結
以上是生活随笔為你收集整理的mybatis入门常见错误的全部內容,希望文章能夠幫你解決所遇到的問題。