2 years ago

#42237

test-img

erezgi1974

spring boot application on apache tomcat

i try to take my spring boot application create war file and deploy to my tomcat server (port 8080) there was a problem that after deploy i got HTTP Status 404 – Not Found

so i create clean spring boot application (via https://start.spring.io with dev and web dependencies and java 11 i add a small controller end service:

@RestController
@CrossOrigin()
public class MyController {

    @GetMapping("/jobs")
    String helloWorld() {
        return "Hello World!";
    }

i add the following to the pom:

<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-tomcat</artifactId>
 <scope>provided</scope>
 </dependency>

and also

<packaging>war</packaging>

in my spring application i add the extend from 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);
 }
}

via maven i run mvn package the created war (first.war) i deploy via the appachi tomcat manager than i go to the apllication url: http://localhost:8080/first/jobs (jobs is one of the end service in the controller) and i got HTTP Status 404 – Not Found

the tomcat version is 9.0.56 any idea ? what am i misssing

java

spring-boot

tomcat

war

0 Answers

Your Answer

Accepted video resources