Manish Jangid
Manish Jangid

Reputation: 31

Spring boot application war not working, Getting 404 when deplying on tomcat server

pom.xml

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.4</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
    <java.version>11</java.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </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>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Main Class

@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(DemoApplication.class);
}
public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
}
}

Controller class

@RestController
public class AppController {

@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test(){
    return "Hello World";
}
}

When I deploy the war I am getting 404. enter image description here

enter image description here

enter image description here enter image description here

I created the war using mvn clean install or mvn package,and deployed on tomcat server, but getting same 404 not found.

Is there any way I can deploy spring boot application war to tomcat?

Upvotes: 1

Views: 723

Answers (1)

lakmali dassanayake
lakmali dassanayake

Reputation: 1

Is there any way I can deploy spring boot application war to tomcat? you can run this command in command prompt. mvnw spring-boot:run

Note: May be you should try this url: http://localhost:8080/test

Upvotes: -1

Related Questions