问题
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:
- 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); } }
- 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>
- 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