java - 在 Eclipse 中将 Spring Boot 应用程序导出为 JAR 文件

标签 java eclipse spring rest maven

我在 Eclipse 中使用 Spring STS 创建一个简单的基于 Web 的 spring boot 项目。我可以在 Eclipse 中正常运行它,但是当我尝试将它导出为 JAR 文件时,我得到:

rg.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

我的 public static void main 位于 Application.java 中,带有 @SpringBootApplication 注释。

我已经仔细检查了所有 Maven 依赖项一百次。

我做错了什么?

最佳答案

很可能,您正在使用内置的 Eclipse 导出器 来生成您的 jar,它只包含该项目中实际生成的目标文件。为了拥有“胖”(独立可执行文件)jar,您需要使用 Spring Boot Maven 或 Gradle 插件来“重新打包”jar。

首先,确保you have the repackage goal included in your build setup ,然后使用 Maven package 目标。最简单的方法是从命令行运行 mvn package(您可能需要为您的操作系统安装 Maven CLI 包);您还可以在 Eclipse 中右键单击 POM 并选择“Run As”以从 Eclipse 中执行特定的 Maven 操作。

关于java - 在 Eclipse 中将 Spring Boot 应用程序导出为 JAR 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37016040/

相关文章:

android - 没有可用于此目标的 cpu/abi 系统镜像

spring - thymeleaf :each two iterate two listings

java - 如何在没有 web.xml 的情况下编写 Encodingfilter 配置

java - 为什么不添加外键约束groovy/grails

java - Java 中 `String` 对象的最大大小是多少?

java - Jersey + Guice + Tomcat 在与根目录以外的其他内容一起提供时生成 404

java - 将 spring bean Autowiring 到自定义 slf4j appender

java - 如何将线程放入数组

java - 如何在 ubuntu 中以 super 用户身份运行 eclipse

java - 无法通过 servlet 连接 mysql;访问被拒绝