首页 > 解决方案 > UnsatisfiedDependencyException:创建名称为“trackiHuntServiceImpl”的 bean 时出错:通过字段“deviceService”表示不满足的依赖关系

问题描述

我正在使用 Spring v1.4.0.RELEASE。我得到一个异常“org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为'trackiHuntServiceImpl'的bean时出错:通过字段'deviceService'表达的不满足的依赖关系”。它的项目是多模块的。

我列出了主要类代码:

    @Import({PrimaryRepositoryConfig.class, 
    AuditRepositoryConfig.class,
    PaypalConfig.class,
    BraintreeConfig.class,
    CommonConfig.class,
    ElasticsearchConfig.class
})
@ComponentScan(basePackages ={"com.trackimo.server.model" ,
        "com.trackimo.server.dao",
        "com.trackimo.server.services",
        "com.trackimo.server.services.account",
        "com.trackimo.server.services.email",
        "com.trackimo.server.services.common",
        "com.trackimo.server.services.location",
        "com.trackimo.server.services.user",
        "com.trackimo.server.services.trackihunt",
        "com.trackimo.server.services.device",
        "com.trackimo.server.audit.model",
        "com.trackimo.server.audit.dao",
        "com.trackimo.server.utils.converters",
        "com.trackimo.server.worker",
        "com.trackimo.quartz.config"},
        excludeFilters = @ComponentScan.Filter(IgnoreDuringScan.class)
)
@SpringBootApplication(exclude = { DispatcherServletAutoConfiguration.class })
@EnableScheduling
@EnableAsync
public class QuartzApplication {

public static void main(String[] args) {
        SpringApplication.run(QuartzApplication.class, args);
    }

}



2019-10-11 16:57:37,072 [main] ERROR o.s.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'trackiHuntServiceImpl': Unsatisfied dependency expressed through field 'deviceService': Error creating bean with name 'deviceServiceImpl': Unsatisfied dependency expressed through field 'emailService': Error creating bean with name 'emailServiceImpl': Unsatisfied dependency expressed through field 'eMailMessageSender': No qualifying bean of type [com.trackimo.server.services.email.DynamicEmailService] found for dependency [com.trackimo.server.services.email.DynamicEmailService]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.trackimo.server.services.email.DynamicEmailService] found for dependency [com.trackimo.server.services.email.DynamicEmailService]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'emailServiceImpl': Unsatisfied dependency expressed through field 'eMailMessageSender': No qualifying bean of type [com.trackimo.server.services.email.DynamicEmailService] found for dependency [com.trackimo.server.services.email.DynamicEmailService]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.trackimo.server.services.email.DynamicEmailService] found for dependency [com.trackimo.server.services.email.DynamicEmailService]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'deviceServiceImpl': Unsatisfied dependency expressed through field 'emailService': Error creating bean with name 'emailServiceImpl': Unsatisfied dependency expressed through field 'eMailMessageSender': No qualifying bean of type [com.trackimo.server.services.email.DynamicEmailService] found for dependency [com.trackimo.server.services.email.DynamicEmailService]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.trackimo.server.services.email.DynamicEmailService] found for dependency [com.trackimo.server.services.email.DynamicEmailService]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'emailServiceImpl': Unsatisfied dependency expressed through field 'eMailMessageSender': No qualifying bean of type [com.trackimo.server.services.email.DynamicEmailService] found for dependency [com.trackimo.server.services.email.DynamicEmailService]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.trackimo.server.services.email.DynamicEmailService] found for dependency [com.trackimo.server.services.email.DynamicEmailService]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

标签: javaspring-boot

解决方案


Spring 无法创建 bean trackiHuntServiceImpl,因为它无法创建 bean deviceServiceImpl,因为它无法创建 bean emailServiceImpl,因为它依赖于未定义的 DynamicEmailService 类型的 bean eMailMessageSender。

基本上,您必须定义一个 DynamicEmailService 类型的 bean。当您解决此问题时,可能还会缺少其他定义。祝你好运。


推荐阅读