初学MyBatis的时候,往往出现的错误都是一些细节上引起的。今天就遇到了一个问题,在运行测试类的时候,出现了以下的错误提示:
org.apache.ibatis.binding.BindingException: Type interface com.haroro.dao.UserDao is not known to the MapperRegistry.
at org.apache.ibatis.binding.MapperRegistry.getMapper(MapperRegistry.java:47)
at org.apache.ibatis.session.Configuration.getMapper(Configuration.java:745)
at org.apache.ibatis.session.defaults.DefaultSqlSession.getMapper(DefaultSqlSession.java:292)
at com.haroro.test.AccountTest.init(AccountTest.java:40)
根据错误提示,发现原来是找不到com.haroro.dao.UserDao,所以经过查看代码,得到了一般出现这样错误的来源:
1.接口的映射配置文件UserDao.xml:
<mapper namespace="com.haroro.dao.UserDao">
写空间名称的时候写错了mapper映射文件的namespace。
2.主配置文件忘记了编写映射文件:
<mappers>
<mapper resource="com/haroro/dao/UserDao.xml"/>
<mapper resource="com/haroro/dao/AccountDao.xml"/>
</mappers>
对于初学者来说,往往会忽略很多细节上的东西,看来还是得多加仔细!!!