简体   繁体   English

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

[英]Deploying WAR file to Jetty: server is running, but application didn't start

I got Spring Boot 2.2.7.RELEASE application.我得到了 Spring Boot 2.2.7.RELEASE应用程序。 Package it as war file and trying to deploy it locally with Jetty: Package 将其作为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();
}

After this Jetty is up and running at localhost:8080 , got no errors in log but it seems like the application didn't start.在此 Jetty 在localhost:8080启动并运行后,日志中没有错误,但似乎应用程序没有启动。 When I try to reach it the response is 404 NOT FOUND.当我尝试到达它时,响应是 404 NOT FOUND。 Although I do see my application directories at localhost:8080 like /swagger-ui/ etc.尽管我确实在localhost:8080上看到了我的应用程序目录,例如/swagger-ui/等。

Drop that code and let Spring Boot handle it.删除该代码并让 Spring Boot 处理它。

Assuming you have an application class named MyRestApplication you need to have the following.假设您有一个名为MyRestApplication的应用程序 class,您需要具有以下内容。

@SpringBootApplication
public class MyRestApplication {

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

Assuming you have Jetty as a dependency as well as spring-boot-starter-web you can just run this class.假设你有 Jetty 作为依赖项以及spring-boot-starter-web ,你可以运行这个 class。

You should also use the spring Boot plugin to create the war or jar and then you can just launch it.您还应该使用 spring 引导插件来创建战争或 jar,然后您可以启动它。

java -jar my-rest-service.war and it will launch everything you need. java -jar my-rest-service.war它将启动您需要的一切。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM