Eclipse STS 使用子项目在本地运行 Spring Boot



我有以下项目结构:

root project
|-- controller
|-- core
|-- widgets
|-- widgetA
|-- widgetB

除了控制器之外,这些项目都内置到jar中。 然后将 jar 部署到类文件夹,控制器使用上下文.xml指定它们的位置。

这一切都在部署期间运行良好(除了 Tomcat 的"重新部署"不会重新部署,我怀疑类加载器有问题,但卸载/部署工作正常(。 但是,我们目前无法在 STS 中本地运行它,因为控制器需要系统无法定位的"widgets"项目中的 bean。

当我将控制器项目作为 Spring 启动应用程序执行时,项目开始正常。 它加载并发现"核心"项目中定义的 bean。 但由于某种原因,"小部件"项目没有被Spring扫描。 同样,当部署它时,Spring 会很好地扫描它们(我假设是因为上下文.xml定义了要加载的 Jar资源(。 但我似乎无法弄清楚如何让 STS "看到"该项目。

编辑:为清楚起见,这是我遇到的错误:

May 22, 2018 2:32:00 PM org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'Controller': Unsatisfied dependency expressed through field 'widgetMap'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.util.Map<java.lang.String, com.mycompany.project.widgets.WidgetInterface>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
System is shutting down
May 22, 2018 2:32:00 PM org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor shutdown
INFO: Shutting down ExecutorService 'getAsyncExecutor'
May 22, 2018 2:32:00 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service [Tomcat]
May 22, 2018 2:32:00 PM org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener logAutoConfigurationReport
INFO: 
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
May 22, 2018 2:32:00 PM org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter report
SEVERE: 
***************************
APPLICATION FAILED TO START
***************************
Description:
Field widgetMap in com.mycompany.project.controller.Controller required a bean of type 'com.mycompany.project.widgets.WidgetInterface' that could not be found.

Action:
Consider defining a bean of type 'com.mycompany.project.widgets.WidgetInterface' in your configuration.

我解决了这个问题。

事实证明,我没有将单个小部件添加到我的构建路径中,而只是将"小部件"类添加到我的构建路径中。

因为我使用的是 @Autowired Map 对象,所以我需要在构建路径上至少有一个WidgetInterface 实现。 由于微件实现项目不存在,因此它无法正确实例化地图,并且出错。

最新更新