在Tomcat上以WAR部署的Spring Boot REST应用程序无法正常工作

创建了一个Spring Boot REST应用程序。

作为Spring启动应用运行
在月食中以 if (code.contains("#")){ Intent i = new Intent(); i.setaction(Intent.actION_DIAL); i.setData(Uri.parse("tel:"+Uri.encode(code))); //here add Uri.encode context.startactivity(i); } 的身份运行时。效果很好。
REST API正在使用URL-spring boot application

在Tomcat上部署为WAR

我遵循以下步骤

  1. 主类扩展了http://localhost:8080/schools
SpringServletContainerInitializer
  1. @SpringBootApplication public class RmsBackendApplication extends SpringServletContainerInitializer { public static void main(String[] args) { SpringApplication.run(RmsBackendApplication.class,args); } } 中添加了开始课程条目
pom.xml
  1. 添加了启动器tomcat依赖项
    <properties>
        <java.version>1.8</java.version>
        <start-class>com.codingParkFun.rmsbackend.RmsBackendApplication</start-class>
    </properties>
  1. 很少有文档说覆盖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> 的{​​{1}}方法。但就我而言,configure没有SpringServletContainerInitializer方法。我下载了Spring Tools 4.0

  2. 使用SpringServletContainerInitializer生成的软件包。战争包裹的生成名称为configure

  3. 在warcat(版本maven install)上部署war软件包

  4. 访问REST API URL-rms-0.0.1-snAPSHOT.war

输出

在Tomcat上以WAR部署的Spring Boot REST应用程序无法正常工作

  1. Tomcat本地主机日志如下:
9.0.27

不确定应用程序REST API何时不起作用。请指导。

zhanghua02302 回答:在Tomcat上以WAR部署的Spring Boot REST应用程序无法正常工作

您需要扩展 SpringBootServletInitializer ,而不是 SpringServletContainerInitializer 。然后,您可以像在步骤4中所说的那样覆盖configure方法,如下所示:

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(RmsBackendApplication.class);
}

希望有帮助!

本文链接:https://www.f2er.com/3133758.html

大家都在问