BindingException异常:Type interface com.niuyun.dao.UserDao is not known to the MapperRegistry.解决了
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>
- 问题解决,可以运行
~希望可以帮助到您,解决问题
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性