我得到了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
,它将启动您需要的一切。