I've followed about 15 different threads on Stack to try and resolve this, but I seem to be hitting a brick wall.
I'm running JDK17 and Tomcat 10.0.22. I have followed a baeldung article for deploying a Spring Boot app on Tomcat, and I'm having no luck at all. I've tried used gradle and maven.
With the provided block commented out, the war runs fine with java -jar spring-boot-deployment.war. However, when activating this line and dragging the war into the web app folder, it doesn't work.
For example, just in spring boot localhost:8080/hello/ works fine
after deploying to Tomcat and going to http://localhost:8080/spring-boot-deployment/hello/ I get The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
I'm not seeing any errors in the Tomcat logs, and the manager says its running. Given how many threads there are on this, it seems to be a pretty poorly documented/understood thing.
@SpringBootApplication
public class SpringBootTomcatApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(SpringBootTomcatApplication.class, args);
}
}
@RestController
public class TomcatController {
@GetMapping(value = "/hello")
public Collection<String> sayHello() {
return IntStream.range(0, 10)
.mapToObj(i -> "Hello number " + i)
.collect(Collectors.toList());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-deployment</artifactId>
<name>spring-boot-deployment</name>
<packaging>war</packaging>
<description>Demo project for Spring Boot</description>
<groupId>com.baeldung.spring-boot-modules</groupId>
<version>1.0.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version>
<relativePath/>
</parent>
<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>
</dependencies>
<build>
<finalName>${artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/conf.properties</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>com.baeldung.springbootsimple.SpringBootTomcatApplication</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>