【mybatis】

【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资源只需要扫描一次就彳亍

posted @ 2022-04-07 22:37  浦西和迪克的爱情故事  阅读(409)  评论(0)    收藏  举报