Mybatis出现:org.apache.ibatis.binding.BindingException: Type interface com.niuyun.dao.UserDao is not known to the MapperRegistry.
的错误,如何解决?
错误如下:
类型接口dao不知道mapper注册中心点的问题
org.apache.ibatis.binding.BindingException: Type interface com.niuyun.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)
! 很明显是没有注册映射的路径
- 查看MyBatis中xml配置文件,其中系统的核心设置
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
</configuration>
- 发现确实少了映射的路径配置,将其加上
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
<!--映射的路径-->
<mappers>
<mapper resource="org/mybatis/example/BlogMapper.xml"/>
</mappers>
</configuration>
- 如果改正后还是出现同样的问题,那么要去看映射路径的.xml文件,其中查看"namespace"的类名是否正确,不正确就改正
<!--名字命名空间--><!--如果使用的是mapper接口的形式, 则namespace 写的就是接口的全类名-->
<mapper namespace="com.qianfeng.dao.UserDao">
<!--resultType 返回值的结果的类型--><!--#{id} 占位符,相当于 ?-->
<select id="getOne" resultType="com.qianfeng.entity.User">
select * from user where id = #{id}
</select>
</mapper>
- 问题解决,可以运行
~希望可以帮助到您,解决问题
~~~感谢您的光临~~~
- BindingException MapperRegistry interface UserDao niuyunbindingexception mapperregistry interface userdao mapperregistry interface xxxmapper mybatis niuyun userdao mapperregistry bindingexception bindingexception invalidbound statement found bindingexception ibatisbinding mybatisplus statement bindingexception selectjoball jobmapper statement mybatissystemexception bindingexception parameters