Skip to content
Advertisement

REST API returning http status 404 when deployed on EC2 instance on AWS

I have a simple spring boot app which has just 2 rest controllers and I am exporting the war for the same. I am deploying the same war using the tomcat manager on EC2 instance on AWS, but unfortunately I am getting http status 404 when trying to hit the API.

URL that I am trying to hit is –

[public IP shared by AWS]:[port number on which tomcat is running:8080]/[context route which is the name of my war file]/[my mapped urls]

[publicIP]:8080/aws-0.0.1-SNAPSHOT/login/code

My Controller class

@RestController
@RequestMapping("/login")
public class TestController {

    @GetMapping("code")
    public String returnCode() {
        return "returning code";
    }

    @GetMapping("received-code")
    public String returnReceivedCode(@RequestParam String code) {
        return code;
    }

}


My pom.xml

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.test</groupId>
    <artifactId>aws</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>aws</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
    </properties>

I tried with java version 8 as well, the tomcat version that I have on my EC2 instance is 9 (apache-tomcat-9.0.70)

I also tried getting one sample war application that tomcat shares for the testing purpose – https://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/

But surprisingly, this is working fine which tells me that my tomcat and java installations don’t have any issues.

Any help would be appreciated.

Advertisement

Answer

As highlighted by @khmarbaise above, I was using spring boot 3.0.0 but I had java 8 installed on my EC2 instance and spring boot 3.0.0 requires java version 17+, and that is why I was getting 404 when hitting my APIs.

After downgrading my spring boot version to 2.7.6 I am able to get a corresponding response from the APIs.

Also, as mentioned by other comments regarding the use of “/”, omitting the slash was not an issue as the slash is an optional parameter.

Thanks

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement