【问题标题】:Why spring-boot app is not working in AWS but works fine in local?为什么 spring-boot 应用程序无法在 AWS 中运行,但在本地运行良好?
【发布时间】:2020-12-18 17:19:26
【问题描述】:

我创建了一个简单的 Hello World Spring Boot 应用程序,它在本地运行良好,但在 AWS ElasticBeanstalk 中部署时出现 404 错误。

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>

在 EBS 中,我创建了一个 Tomcat 环境,并将这场战争部署在 Tomcat 环境中。

我做错了什么?

【问题讨论】:

  • 在用@SpringBootApplication 注释的类中,你是否也继承自SpringBootServletInitializer。这是允许 Tomcat 启动应用程序上下文所必需的。

标签: java amazon-web-services spring-boot amazon-elastic-beanstalk


【解决方案1】:

假设您的 WAR 文件名为 test.war,那么要访问的正确 URL 应该是:

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

port 应该是你的 tomcat 端口,如果你没有更改它是 80,而不是你的 application.properties 中设置的server.port

【讨论】:

【解决方案2】:

您应该将您在 aws 中的端口更改为端口 5000。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-21
    • 1970-01-01
    • 1970-01-01
    • 2017-04-19
    • 1970-01-01
    • 2012-12-09
    相关资源
    最近更新 更多