org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML.问题思路

15:36:34,549  WARN DefaultListableBeanFactory:1416 - Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemsMapper' defined in file [F:\apache-tomcat-7.0.77\webapps\ssm0531\WEB-INF\classes\cn\com\dao\ItemsMapper.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Wrong namespace. Expected 'cn.com.dao.ItemsMapper' but found 'cn.com.mapper.ItemsMapper'.
15:36:34,549  WARN XmlWebApplicationContext:487 - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private cn.com.dao.ItemsMapper cn.com.service.ItemServiceImpl.itemsMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [cn.com.dao.ItemsMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemsMapper' defined in file [F:\apache-tomcat-7.0.77\webapps\ssm0531\WEB-INF\classes\cn\com\dao\ItemsMapper.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Wrong namespace. Expected 'cn.com.dao.ItemsMapper' but found 'cn.com.mapper.ItemsMapper'.
	

在第一次常识整合SSM的时候爆了一个异常,说namespace错误,有效信息如下:

Cause: org.apache.ibatis.builder.BuilderException: Wrong namespace. Expected 'cn.com.dao.ItemsMapper' but found 'cn.com.mapper.ItemsMapper'.

我就在application-dao.xml查看是不是包扫描器有问题,找了半个小时也没看到我那里有个Mapper配的叫做cn.com.mapper.ItemsMapper,然后我就疯了,但是我冷静下来想想,既然配置的是自动包扫描,如果是手动配置的话,肯定要把接口对应的****mapper.xml配到application-dao.xml中,但是我使用的是自动扫描,那么myBatis肯定是去解析我的application-dao.xml中的一些内容,肯定包括namespace等等。

我去找了具体的***mapper.xml文件,看里面的namespace,果不其然,写成了cn.com.mapper.ItemsMapper'。

回头想想原因,我这几个***mapper.xml映射文件,是用MyBatis提供的逆向工程工具,自动生成的,然后指定的包名,和后来复制目的地的包名不一致,导致框架自动解析器解析不到对应的内容,所以就会报错。

记录一下启动成功的截图

org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML.问题思路_第1张图片

你可能感兴趣的:(Web进阶,MyBatis)