@org.springframework.beans.factory.annotation.Autowired(required=true)

来源:互联网 发布:mac ae插件怎么安装 编辑:程序博客网 时间:2024/05/29 18:10
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"/>
2 4