简体   繁体   中英

When Spring Boot app is deployed on tomcat gives 404 error

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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