【mybatis】

您所在的位置:网站首页 浦西女王与迪克王子 【mybatis】

【mybatis】

2024-07-08 09:31| 来源: 网络整理| 查看: 265

【ERROR】 Type interface com.kg.dao.bookMapper is not known to the MapperRegistry.

mapper未注册??

【总结】没有扫描XML 或者namespace写错了

【ERROR】Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mapper.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis-config.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com.kg.dao.bookMapper.xml

image

原因是写mapper文件资源时用.分隔 实际上这里寻找的是资源地址URL所以应该用/

image

【总结】mapper文件资源地址用 / 分隔

【ERROR】Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mapper.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\IdeaProjects\ssmProjectDemo\target\classes\com\kg\dao\bookMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [E:\IdeaProjects\ssmProjectDemo\target\classes\com\kg\dao\bookMapper.xml]'. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.kg.dao.bookMapper.addBook. please check com/kg/dao/bookMapper.xml and file

image

image

image 扫描了2次mapper.xml 去掉其中一处即可

【总结】mapper资源只需要扫描一次就彳亍



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3