Spring运行时报错:No matching bean of type xxxx

遇到了一个问题,在项目中启动调试时,发现报错No match bean错误,报错信息如下:

com.xxx.xxx.framework.exception.UnknowGeneralException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sendSMSService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.xxx.xxx.module.xxx.server.service.IConfigurationParamsService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(mappedName=, shareable=true, description=, name=, type=class java.lang.Object, lookup=, authenticationType=CONTAINER)} at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:306) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)

看报错信息知道是sendSMSService注入IConfigurationParamsService时发生,检查代码后发现,IConfigurationParamsService已经在配置文件中注入,并且在同包下的其他类中可以正常使用,并且按照正常来说,如果是因为未配置的bean,应该在启动时报错,而不是在运行时报错,一时间搞不清楚问题在哪。

后来再次检查代码,发现sendSMSService不是通过注解或者配置文件的方式注入的,而且在获取此service时,使用的是applicationContext.getBean(‘sendSMSService’)方法,而IConfigurationParamsService是引用的jar包中的service,在applicationContext中不能扫到此service,所以报错,至此,问题就好解决了。
于是在调用sendSMSService方法的地方,先使用@Resource标签注入IConfigurationParamsService,并把此service作为参数传入,问题解决。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值