0

Spring Boot application runs normally on embedded Tomcat server when I run it from Eclipse, but when I deploy it to external tomcat server (on Windows) I'm getting HTTP 404 status.

I did clean package and copied from target folder war file in tomcat webapps folder on local tomcat server and I restarted tomcat but...

When I run get method in postman with endpoint http://localhost:8080/export/test/ I get 404 not found

Tomcat version 9
Java 11

TOMCAT MANAGER:

enter image description here

@SpringBootApplication
public class ExportApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(ExportApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(ExportApplication.class);
    }
}

POM file:

<?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.6.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>bojankosta</groupId>
    <artifactId>export</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>export</name>
    <description>Export db</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>11</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>

    </dependencies>

    <build>
        <finalName>${artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

application.properties:

server.servlet.context-path=/export

Controller:

package bojankosta.export.controller;

import bojankosta.export.service.ContinentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BasicController {

       @Autowired
       private ContinentService continentService;

       @GetMapping("/")
       public String getAllData()  {
              return continentService.export();
       }

       @GetMapping("/test")
       @ResponseBody
       public String currentUserName() {
              return "Hello";
       }

}



0

2 Answers 2

0

404 means that url you are hitting is not available.When We deploy the code on external application server it serves it from root context that is generally start with the project name . You can check in the logs what is context it is serving and then append the rest end point it .It will work

Sign up to request clarification or add additional context in comments.

3 Comments

It should be like filename "export"
Can you send me some simple war file or project to test is it going to work when I copy it on my local tomcat
You need to set the application context in tomcat and it can be done by following steps -- Edit Configuration --> tomcatServer( the tomcat server you are using) ->under that go to deployment tab -> you will find Application context for your war deployed -> set it to /export .
0

You can use finalName property in your build file (pom.xml for maven)

<finalName>export</finalName>

1 Comment

I did that <finalName>${artifactId}</finalName>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.