运行spring项目出现{@org.springframework.beans.factory.annotation.Autowired(required=true)}

运行spring项目时出现org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'xyz.newtouch.Xxx': Unsatisfied dependency expressed through field 'Xxx'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'xyz.newtouch.service.Xxx' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}错误,出现此错误的原因是自动注入失败:

  • 需要检查对应组件是否被对应注解修饰,或需要注入的对象是否被配置到ioc,也可指定required属性为false指定未成功注入时不直接抛出异常(为null)。
  • 检查注解扫描路径是否正确
    <!-- 指定注解扫描路径 -->
    <context:component-scan base-package="xyz"/>
    
©️2020 CSDN 皮肤主题: 撸撸猫 设计师:设计师小姐姐 返回首页