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提供的逆向工程工具,自动生成的,然后指定的包名,和后来复制目的地的包名不一致,导致框架自动解析器解析不到对应的内容,所以就会报错。

记录一下启动成功的截图


  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 12
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值