将 WAR 文件部署到 Jetty:服务器正在运行,但应用程序未启动



我得到了Spring Boot2.2.7.RELEASE应用程序。将其打包为war文件,并尝试使用 Jetty 在本地部署它:

public static void startJetty() throws Exception {
Server server = new Server(8080);
WebAppContext context = new WebAppContext();
context.setContextPath("/");
File warFile = new File("target/rest-service/my-rest-service.war");
context.setWar(warFile.getAbsolutePath());
server.setHandler(context);
server.start();
server.dumpStdErr();
server.join();
}

在此 Jetty 启动并在localhost:8080运行后,日志中没有错误,但似乎应用程序没有启动。当我尝试到达它时,响应是 404 未找到。虽然我确实在/swagger-ui/localhost:8080看到我的应用程序目录。

删除该代码,让 Spring Boot 处理它。

假设您有一个名为MyRestApplication的应用程序类,则需要具有以下内容。

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

假设您有 Jetty 作为依赖项以及spring-boot-starter-web您可以运行此类。

您还应该使用 spring Boot 插件来创建战争或 jar,然后您可以启动它。

java -jar my-rest-service.war,它将启动您需要的一切。

相关内容

最新更新