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.
Asked
Active
Viewed 7,901 times
0
-
This is useful to know too. When I needed to, I missed this:"Applications that run on Tomcat 9 and earlier will not run on Tomcat 10 without changes. Java EE based applications designed for Tomcat 9 and earlier may be placed in the $CATALINA_BASE/webapps-javaee directory and Tomcat will automatically convert them to Jakarta EE and copy them to the webapps directory." – Perkone Apr 07 '22 at 08:08
1 Answers
6
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.

Mahesh_Loya
- 2,743
- 3
- 16
- 28
-
-
Hi @Mahesch_Loya thanks for the solution. My spring boot app is deployed in the tomcat /attributes directory. I do not understand if I need to set the server.context property in the application.properties? My controller is expecting @RequestMapping("/") and when I go to https://servername/attributes/ I receive 404. The application was working fine locally responding to localhost:8080. My question is do i need server.servlet.context-path=/attributes in my application.properties. – Ana Sustic Sep 09 '21 at 08:44
-
1@Ana Sustic Is it possible for you to share a git link of your sample project? I will check and update. – Mahesh_Loya Sep 10 '21 at 15:22
-
1Hi @Mahesh_Loya thanks for the offer. I solved it. I had an incorrect end point. – Ana Sustic Sep 19 '21 at 15:04