简体   繁体   中英

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?

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.

you should change your port in aws to port 5000.

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM