java - 将 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 NOT FOUND。虽然我确实看到了我的应用程序目录localhost:8080
等/swagger-ui/
。
解决方案
删除该代码并让 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
它会启动你需要的一切。
推荐阅读
- java - 握手方的递归调用
- java - 一页上实体实例的多种形式 - 未创建表单
- css - Vuetify 主题不适用于自定义主题
- c# - 来自 C# 的 LSP 悬停文本降价链接不起作用
- command-line-interface - Zapier CLI,有没有办法改变输出的显示顺序
- ubuntu - xfce4 via VcXsrv Server on wsl2 与 DPI 问题
- python - 如何在 3D 阵列的特定一侧应用 2D 蒙版?
- swiftui - SwiftUI - 将项目从一个列表拖到另一个
- python - 将 if 语句条件与用户输入语句匹配(减少多个条件)
- swift - NSEvent.addLocalMonitorForEvents 在没有窗口的应用程序开发中不起作用(构建 macOS 菜单栏应用程序)