使用SSM框架整合时,无法创建XXXXBean

异常是这样的

Error creating bean with name 'searchItemServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private cn.e3mall.search.mapper.ItemMapper cn.e3mall.search.service.impl.SearchItemServiceImpl.itemMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [cn.e3mall.search.mapper.ItemMapper] 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)}

Spring注入失败,我的第一反应也是没有打@Service注解,或者是@Service的包导错了(因为alibaba 也有个这样的包)。

但是经过检查并没有问题。碰到这类型的错误真的是蛋疼,浪费了不少时间。


最后一步步排查发现是这个类中间的定义的一个成员变量注入错误,并不是网上说的 @Service @AutoWired的都有问题。

原因是: Mybatis框架配置文件中的扫描的路径错误(配置文件配置的Bean),导致Spring不能注入到那个成员变量里面去。我这么表达也不是很清楚,不过总结一句:

碰到注入失败的错误,如果不是没有打注解,那有可能是配置文件的扫描位置写错了,不一定只在applicationXXX.xml文件里面,还可能是其他的配置文件里写错了。多找找吧。委屈好麻烦。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值