第一个mybatis程序的报错-Type interface com.xiaoma.mapper.UserMapper is not known to the MapperRegistry

第一个mybatis程序的报错-Type interface com.xiaoma.mapper.UserMapper is not known to the MapperRegistry

刚开始学mybatis框架,运行的第一个程序就出现了错误,用测试类读取数据库表中数据的时候报错

错误原因1:UserMapper.xml中没有和接口进行绑定

解决方法:将namespace改成dao层(mapper层)的接口文件即可,我的接口的路径是java/com/xiaoma/mapper/UserMapper,所以对应的namespace为:com.xiaoma.mapper.UserMapper

错误原因2:项目读取不到java文件夹下的配置文件

解决办法:在项目的pom.xml文件添加如下代码

 1 <!--    设置资源目录,使其可以读取dao(mapper)下xml文件-->
 2     <build>
 3         <resources>
 4             <resource>
 5                 <directory>src/main/java</directory>
 6                 <includes>
 7                     <include>**/*.properties</include>
 8                     <include>**/*.xml</include>
 9                 </includes>
10                 <filtering>true</filtering>
11             </resource>
12             <resource>
13                 <directory>src/main/resources</directory>
14                 <includes>
15                     <include>**/*.properties</include>
16                     <include>**/*.xml</include>
17                 </includes>
18                 <filtering>true</filtering>
19             </resource>
20         </resources>
21     </build>
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » 第一个mybatis程序的报错-Type interface com.xiaoma.mapper.UserMapper is not known to the MapperRegistry