【问题标题】:Springboot buildSpring Boot 构建
【发布时间】:2021-02-28 23:00:17
【问题描述】:

我有一个基于 Springboot 框架构建的系统,它运行两个服务,如图所示:

我需要构建 stock-quote-manager 以将其容器化。 我尝试使用 mvnw 以这种方式构建它:

./mvnw spring-boot:build-image

但它引发了一个错误,让我相信我需要重构整个代码,将 stockquotemanager 或 stockmanager 移动到另一个包。有没有其他方法可以在不进行任何重构的情况下构建它?

这是 mvnw 错误:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  33.107 s
[INFO] Finished at: 2021-02-28T10:33:14-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.3:repackage (repackage) on project stock-quote-manager: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.4.3:repackage failed: Unable to find a single main class from the following candidates [com.br.inatel.stockmanager.StockManagerApplication, com.br.inatel.stockquotemanager.StockQuoteManagerApplication] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

我不知道这是否相关,但 StockManager 在端口 8080 上运行,stockQuoteManager 在端口 8081 上运行。

提前致谢,

【问题讨论】:

    标签: java spring-boot


    【解决方案1】:

    您收到此错误是因为您对一个项目、StockQuoteManagerApplication 和 StockManagerApplication 有多个主要方法。您必须将这两者分开并在单独的 tomcat 实例中运行它们(即创建两个不同的项目),然后您才能为每个服务获得两个单独的端口。因为它们都在同一个 tomcat 实例中运行,所以只会提供一个端口。

    【讨论】:

      【解决方案2】:

      在 Project 文件夹中添加一个Docker 文件,并按照 Spring 官方文档中的说明执行以下操作。

      Spring Boot with Docker 谢谢。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-19
        • 2022-01-22
        • 2016-09-29
        • 2019-02-05
        • 2018-10-18
        • 2023-01-28
        • 2022-01-10
        • 1970-01-01
        相关资源
        最近更新 更多