沉梦昂志296 2022-02-13 01:37 采纳率: 0%
浏览 79

UnsatisfiedDependencyException异常报错求解!

问题遇到的现象和发生背景

浏览器一直500报错 HTTP Status 500 - Servlet.init() for servlet DispatcherServlet threw exception
Error creating bean with name 'demoController': Unsatisfied dependency expressed through field 'demoService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.hjbnb.service.DemoService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

问题相关代码,请勿粘贴截图

@Controller
public class DemoController {
@Autowired
private DemoService demoService;

@RequestMapping(value = "/show")
public String show() throws FileNotFoundException, MyException {
    System.out.println("show running......");
    //demoService.show1();
    //demoService.show2();
    //demoService.show3();
    //demoService.show4();
    demoService.show5();
    return "index";
}

}

运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

4条回答

  • 陆小叁 2022-02-13 01:54
    关注

    看看DemoService被扫描到了吗?如果没有被spring容器进行管理。是不能用@Autowired注解的。

    评论

报告相同问题?

问题事件

  • 创建了问题 2月13日