1、在对mybatis进行测试的时候报错:org.apache.ibatis.binding.BindingException: Type interface pers.zhb.dao.StudentDao is not known to the MapperRegistry。已经检查了核心配置文件和mapper.xml,并未发现异常,查询相关资料大多提示是mapper.xml的namespace配置错误,但是这里并未发现错误
2、错误原因
没有将mapper.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> <properties resource="jdbc.properties"/> <environments default="development"> <environment id="development"> <!-- 使用jdbc事务管理 --> <transactionManager type="JDBC" /> <!-- 数据库连接池 --> <dataSource type="POOLED"> <property name="driver" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </dataSource> </environment> </environments> <mappers> <mapper resource="pers.zhb.dao/StudentMapper.xml"></mapper> </mappers> </configuration>
添加代码将mapper.xml文件引入到mybatis的核心配置文件。