简体   繁体   English

在AWS Elastic Beanstalk上部署Spring Boot应用程序 - 获得502错误

[英]Deploying Spring Boot app on AWS Elastic Beanstalk — getting 502 error

I know, there are a lot of such quesions and answers here, but none of them helped me. 我知道,这里有很多这样的问题和答案,但没有一个能帮助我。 I try to install my simple Spring Boot app on AWS Elastic Beanstalk. 我尝试在AWS Elastic Beanstalk上安装我的简单Spring Boot应用程序。 There is a limitation: it must use .jsp templates, so it's .war , not .jar . 有一个限制:它必须使用.jsp模板,所以它是.war ,而不是.jar If I use predefined Tomcat env on Elastic Beanstalk, everything works fine, but my goal is to use Java env. 如果我在Elastic Beanstalk上使用预定义的Tomcat环境,一切正常,但我的目标是使用Java环境。

When I install my app, its status is getting Degraded and I become 502 when trying to reach the url. 当我安装我的应用程序时,其状态正在Degraded ,当我尝试访问该网址时,我变为502。

Locally everything works perfect. 在当地一切都很完美。

I changed port in application.properties to 5000, but it didn't help. 我将application.properties端口更改为5000,但它没有帮助。 I found a recommendation to use a security rule for inbound for TCP Port 5000 "0.0.0.0/32" but it didn't help eather. 我发现建议对TCP Port 5000 "0.0.0.0/32"入站使用安全规则,但它没有帮助收集。

Here are my pom.xml dependencies: 这是我的pom.xml依赖项:


    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.eclipse.jdt.core.compiler</groupId>
            <artifactId>ecj</artifactId>
            <version>4.6.1</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

application.properties: application.properties:

spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp
server.port=5000

Main Java class: 主Java类:

@SpringBootApplication
public class DemowebApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(DemowebApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(DemowebApplication.class, args);
    }

}

AWS error logs: AWS错误日志:

2019/05/07 21:04:45 [error] 7827#0: *19 connect() failed (111: Connection refused) while connecting to upstream, client: 91.232.158.8, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "my-endpoint-tst.us-east-2.elasticbeanstalk.com"
2019/05/07 21:04:46 [error] 7827#0: *19 connect() failed (111: Connection refused) while connecting to upstream, client: 91.232.158.8, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "my-endpoint-tst.us-east-2.elasticbeanstalk.com", referrer: "my-endpoint-tst.us-east-2.elasticbeanstalk.com/"

I suspect that problem is with my Tomcat configuration, but all my experiments with it didn't help yet. 我怀疑问题出在我的Tomcat配置上,但我的所有实验都没有帮助。

I had a similar issue with this. 我有一个类似的问题。 I would load the JAR up to Elastic Beanstalk and when I would try to access the URL, I would get the 502 Apache error with the degraded status. 我会将JAR加载到Elastic Beanstalk,当我尝试访问URL时,我会得到具有降级状态的502 Apache错误。 Locally, I was set to port 8080 but when I tried to access it through my URL I was getting the 502. My problem was: 在本地,我被设置为端口8080,但是当我尝试通过我的URL访问它时,我得到了502.我的问题是:

1) I was not exporting and uploading the fat .JAR file from my IDE when I was exporting it. 1)我在导出时没有从IDE导出和上传胖.JAR文件。 I know you said you cant use .JAR but just make sure when you are exporting your project, you are also exporting all the dependencies from Maven with it. 我知道你说你不能使用.JAR但是只要确保在导出项目时,你也要用它来导出Maven的所有依赖项。

2) This might be a bigger help than the first part of this answer but even when I was putting my port in the application.properties, it wasn't pulling through to the Elastic Beanstalk instance. 2)这可能比这个答案的第一部分有更大的帮助,但即使我把我的端口放在application.properties中,也没有提到Elastic Beanstalk实例。 What I successfully ended up doing to solve this issue was going into the management console in AWS, going to my Beanstalk instance, and going to the configuration tab. 我成功完成解决此问题的工作是进入AWS的管理控制台,转到我的Beanstalk实例,然后转到配置选项卡。

On the configuration tab there is a section Software and in that subsection, go to the Environment Properties. 在配置选项卡上有一个软件部分,在该子部分中,转到环境属性。 In the Name section of the environment properties, enter SERVER_PORT and for the value section, enter 5000 . 在环境属性的“名称”部分中,输入SERVER_PORT ,对于值部分,输入5000 Click apply and let the instance restart. 单击“应用”,然后重新启动实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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