REST API works locally, but does not work on TOM CAT

Asked

Viewed 101 times

0

I am uploading a Rest API locally and making requests normally with POSTMAN in this API, but when I upload this same API to Tomcat, it simply misses 404 and I don’t have access to any of the API methods.

This is my 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 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>br.com.consiste</groupId>
    <artifactId>xtr-util</artifactId>
    <version>1.0.0</version>
    <packaging>war</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <name>xtr-util</name>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.ibm</groupId>
            <artifactId>lotus-domino</artifactId>
            <version>1.0.2</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </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-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20180813</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
        </dependency>

    </dependencies>

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

</project>

Not even the simplest method works on Tomcat.

@CrossOrigin
@GetMapping("/session")
public ResponseEntity<String> checkConnection() {
    return new ResponseEntity<String>("Conexão Estabelecida com a API", HttpStatus.OK);
}

Obs:

Running locally I see the execution of Spring, but when climbing the application in TOMCAT does not appear this execution, could be the error?

1 answer

0

You must follow the guidelines according to spring boot documentation

1) Leave the embedded server dependency as provided:

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

2) Change the Packaging of your pom.xml for <packaging>war</packaging> (you’ve already done it)

3) To generate WAR, use Goal package Maven, also as pointed out by documentation

An example of pom.xml for traditional deploy can be found here.

  • I’ll see if there’s anything in the documentation that helps me, thank you

  • Unfortunately it was already using this dependency, and still not working

  • Did you by any chance change the application’s context path? Shows an error on startup?

  • does not present any initialization error, simply when calling the routes by Tomcat there is the error: HTTP Status 404 - Not Found. Where would the application’s context path be? I have this request: @Requestmapping("/api") E I call @Getmapping("/Session")

  • I added a detail at the end, if you could take a look.

  • @Matheusribeiro is probably the reason it’s not working.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.