Could not autowire. No beans of ‘MenuService’ type found. more…
前言:
- 学习技术对于我们来说是无止境的,只有不断地学习,才能适应技术的快节奏迭代.
一.问题:
- 不能引用@Autowired
- Could not autowire. No beans of ‘MenuService’ type found. more…
二.详情:
Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'menuController': Unsatisfied dependency expressed through field 'menuService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.qf.service.MenuService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
经过分析以及对网上资料的搜集,发现是相关的包没有扫描到
- 解决方案: 将包的扫描添加上
<context:component-scan base-package="com.qf.service,com.qf.controller,com.qf.mapper"/>
- 注意: 需在对应的impl中添加组件标签,若没有添加相应的标签也会出现上述错误
- 例
希望能够帮助到您 ^ - ^