首页 > 解决方案 > 一堆更改后如何解决 UnsatisfiedDependencyException

问题描述

嗨,我是 Spring 世界的新手,需要一些想法来解决这个问题。在我更新了一堆文件后,Spring Web 服务无法成功启动。

TestMainApplication是我的主要引导文件。

我相信根本原因来自chartServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 6; 但是,我还没有从secondaryChannelServiceImpl.

有什么想法或方向来研究这类问题吗?

构造函数重复问题还是?

    at com.iicloud.goodOrg.TestMain.service.TestMainApplication.main(TestMainApplication.java:69)

    Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: 

    Error creating bean with name 'org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration': Unsatisfied dependency 
    expressed through method 'setConfigurers' parameter 0; 
    nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'TestMainApplication': 
    Unsatisfied dependency expressed through field 'chartService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'chartServiceImpl' defined in file [.../charts/service/impl/chartServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 6; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'secondaryChannelServiceImpl' 

标签: springspring-mvc

解决方案


UnsatisfiedDependencyException 可能由于多种原因而发生。

  • 如果我们没有为特定类创建 bean,或者我们错过了该类的 @Component 注释。Spring 不会管理这些类,因此 Spring 容器不会创建要自动装配的对象。

  • 不属于组件扫描的包的自动装配类。Spring 将仅在包扫描中包含的包中搜索组件。

  • 如果存在非唯一的依赖解决方案。如果一个接口有两个以上的实现,Spring 将不知道要自动装配哪一个。这可以通过使用@Qualifier 注释和@Autowired 提及正确的实现来避免。


推荐阅读