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.
CodePudding user response:
You have to add a "/" before "code"
@GetMapping("/code")
CodePudding user response:
you forgot to add / for your path in controller methods because of you use path:
/logincode
instead /login/code