When Spring Boot app is deployed on tomcat gives 404 error

大城市里の小女人 提交于 2021-01-07 02:31:30

问题


Spring Boot application runs on embedded tomcat server when run it from Eclipse or intellij idea. But when deployed on external tomcat server it gives 404 error.


回答1:


Make sure you have done below steps:

  1. Extends SpringBootServletInitializer
@SpringBootApplication
 public class SpringBootWebApplication extends SpringBootServletInitializer 
{

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

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

 }
  1. Marked the embedded servlet container as provided in you pom.xml
<!-- marked the embedded servlet container as provided -->
  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <scope>provided</scope>
  </dependency>
  1. Update packaging to war

<packaging>war</packaging>

  • Copy the generated war into Tomcat`s webapp folder and re-start tomcat.
  • Go to admin page of tomcat and see if you can find your your app and its status is running/started.While accessing URL make sure you are appending right context path,if defined using "server.context" property in application.properties file.

Paste any specific error in case otherwise,if you still face the issue.



来源:https://stackoverflow.com/questions/49305090/when-spring-boot-app-is-deployed-on-tomcat-gives-404-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!