java - 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)}
解决方案
Spring 无法创建 bean trackiHuntServiceImpl,因为它无法创建 bean deviceServiceImpl,因为它无法创建 bean emailServiceImpl,因为它依赖于未定义的 DynamicEmailService 类型的 bean eMailMessageSender。
基本上,您必须定义一个 DynamicEmailService 类型的 bean。当您解决此问题时,可能还会缺少其他定义。祝你好运。
推荐阅读
- angular - nosuchsessionerror: 无效的会话ID - Docker for linux | 量角器
- sql - 使用 rand() sql(Athena Presto)按组(不是行)重复样本
- c# - 如何在我的 C# 应用程序中调用第三方 exe?
- javascript - 尝试获取推送通知的博览会设备令牌的错误消息
- html - 相对路径不适用于标题菜单中的一个元素?
- vim - 如何使用 vim 全局命令剪切和复制以注册多行匹配模式(g :)
- c - 使用 C 编程在 inotify_add_watch 中拒绝权限
- azure-devops - 多阶段发布管道变量值在重新运行期间被当前值覆盖
- c++ - int&b = (&a)是什么语法[15]
- webpack - Karma webpack mocha 记者。错误堆栈未格式化