'Tomcat 404 when deploying a war file which otherwise works in IntelliJ
I've been trying to create a WAR file and deploy it on a Tomcat server. If I run the WAR file WITHIN IntelliJ on a Tomcat server, it works.
To make things as simple as possible, I followed this tutorial (https://www.baeldung.com/spring-boot-war-tomcat-deploy) and even that one doesnt work. I still get the same 404 error when deploying the war file. The tutorial application works within IntelliJ just like my main project does. I am fairly new and have tried plenty of things to no avail:
Tried to either set the line war in the pom.xml file, clean maven and use the resulting war file from the target folder for the Tomcat server deployment or explicitly built the war artifact following the official website ( https://www.jetbrains.com/help/idea/deploying-a-web-app-into-an-app-server-container.html) and tried to run that.
Tried different URLs but all of them throw the 404 error (except for the default Tomcat pages like /manager)
Setting a different path in the application.properties file (server.servlet.context-path=/test)
Tried a different computer
The error:
What newbie mistake might I be making?
My pom:
<?xml version="1.0" encoding="UTF-8"?>
https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot spring-boot-starter-parent 2.2.5.RELEASE com.example tomcat-test2 0.0.1-SNAPSHOT war tomcat-test2 Demo project for Spring Boot
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
My Controller:
@RestController
public class TomcatController {
@GetMapping("/hello")
public Collection<String> sayHello() {
return IntStream.range(0, 10)
.mapToObj(i -> "Hello number " + i)
.collect(Collectors.toList());
}
}
The Main Application:
@SpringBootApplication public class TomcatTest2Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(TomcatTest2Application.class, args);
}
}
Thanks in advance, Alex
Solution 1:[1]
I solved a similar problem by changing the tomcat version. My war file was getting 404 on Tomcat 10, I got rid of the problem using Tomcat 9.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alperen Çetin |

