'Why spring-boot app is not working in AWS but works fine in local?

I have created a simple Hello World Spring Boot Application that works fine in local but gives a 404 error when deployed in AWS ElasticBeanstalk.

HelloController.java

@RestController
@RequestMapping("/")
public class HelloController {
    
    @GetMapping("hello")
    public String result() {
        return "Hello World";
    }

}

application.properties

server.port = 8080
spring.datasource.url=<RDS ENDPOINT>
spring.datasource.username=<username>
spring.datasource.password=<password>

In the EBS, I created a Tomcat Environment, and deployed this war in the Tomcat Environment.

What I'm doing wrong ?



Solution 1:[1]

Let's assume your WAR file is named test.war, then the right URL to visit should be :

http://your-domain:port/test/hello

And the port should be your tomcat port, which is 80 if you haven't changed it, not the server.port set in your application.properties.

Solution 2:[2]

you should change your port in aws to port 5000.

Solution 3:[3]

for people still getting this error or getting error in health check.

first and foremost please check env logs via awsebcli or on-site you will find your major application problem here.

in most cases, you might have compiled your spring boot application in a different JDK and the AWS server is using different JDK so please check the version.

check on which port your Nginx server is running and then change that in your application properties.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Abrar Ansari
Solution 3 Bhavesh Audichya