I have a Spring Boot application (using Gradle build tool) that I would like to deploy using Tomcat 10. I create the war, deploy it using Tomcat Manager App (or drag and drop the war under tomcat installation /webapps), and then open it, but I always get 404 with message "The requested resource is not available".
To test if something was wrong with my app, I created a completely new demo app with one controller and endpoint, that should return a string. This didn't work either.
Then I tried to follow a tutorial (https://www.youtube.com/watch?v=OEx_V1q04tg&ab_channel=DailyCoding). I followed it step-by-step, but still I always get a 404 response.
I also tried to find help elsewhere (for example here, https://www.codejava.net/java-ee/servlet/solved-tomcat-error-http-status-404-not-found), but no help.
Here is my demoapp build.gradle:
plugins {
id 'org.springframework.boot' version '2.4.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'war'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
}
test {
useJUnitPlatform()
}
Here is DemoApplication.java:
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(DemoApplication.class);
}
}
Controller:
package com.example.demo.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloController {
@RequestMapping("/")
public String sayHello() {
return "Hello from DemoApplication!";
}
}
Any help is appreciated.