org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'paymentOrderController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.chaoge.service.paymentOrderService com.chaoge.controller.paymentOrderController.pos; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.chaoge.service.paymentOrderService] 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)}
由于自己平常做项目时喜欢喜欢各种尝试,所有特别多奇葩错误!今天遇到了这个问题搞了半天,在网上也看了下别人的错误,和我的有点不一样,突然想到配置springMvc只配置了controller扫描注入,未配置service扫描注入,所以使用@Autowired无法注入报错!分享一下,也给以后留个答案!
在springMvc文件中配置以下代码就可以了:
<!-- 扫描controller,service(controller,service层注入) -->
<context:component-scan base-package="com.chaoge.controller"/>
<context:component-scan base-package="com.chaoge.service"/>

Logo

脑启社区是一个专注类脑智能领域的开发者社区。欢迎加入社区,共建类脑智能生态。社区为开发者提供了丰富的开源类脑工具软件、类脑算法模型及数据集、类脑知识库、类脑技术培训课程以及类脑应用案例等资源。

更多推荐