简体   繁体   中英

AWS Elastic Beanstalk - Problem with tomcat java spring boot application

Do you have any idea what I can't access my application hosted on Amazon Elastic Beanstalk?

Configuration: Tomcat 8.5 with Java 8 running on 64bit Amazon Linux/3.0.6 My app: Java spring boot application

On my localhost, everything is working fine.

I've set the server.port = 5000 in my application.properties file.

When i trying to get my app login page using link:

http://testenv-env.eu-west-1.elasticbeanstalk.com/employee/login

I received and 404 error:

HTTP Status 404 – Not Found Type Status Report

Message /employee/login

but when I add a port to the link:

http://testenv-env.eu-west-1.elasticbeanstalk.com:5000/employee/login

the error is: This site can't be reached.

My security group configuration:

在此处输入图片说明

/var/log/tomcat8/localhost_access_log.txt

127.0.0.1 - - [17/Nov/2018:10:19:04 +0000] "GET / HTTP/1.1" 404 1074
127.0.0.1 - - [17/Nov/2018:10:21:16 +0000] "GET /employee/login HTTP/1.1" 404 1092
127.0.0.1 - - [17/Nov/2018:10:29:02 +0000] "GET / HTTP/1.1" 404 1074
127.0.0.1 - - [17/Nov/2018:10:29:56 +0000] "GET /employee/login HTTP/1.1" 404 1092

/var/log/httpd/error_log

[Sat Nov 17 10:19:18.529071 2018] [mpm_worker:notice] [pid 3716:tid 140569196038208] AH00295: caught SIGTERM, shutting down
[Sat Nov 17 10:19:22.241929 2018] [ssl:warn] [pid 25414:tid 140137380542528] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]
[Sat Nov 17 10:19:22.243341 2018] [mpm_worker:notice] [pid 25414:tid 140137380542528] AH00292: Apache/2.4.34 (Amazon) OpenSSL/1.0.2k-fips configured -- resuming normal operations
[Sat Nov 17 10:19:22.243372 2018] [core:notice] [pid 25414:tid 140137380542528] AH00094: Command line: '/usr/sbin/httpd'

and my pom.xml dependencies:

<groupId>com.project</groupId>
    <artifactId>iam</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>iam</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

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

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
<dependency>
 <groupId>org.webjars</groupId>
 <artifactId>bootstrap</artifactId>
 <version>4.0.0</version>
</dependency>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
    </dependency>


    </dependencies>

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

First step would be check your URL

http://iam-env.eu-west-1.elasticbeanstalk.com/employee/login

itself looks incorrect. It is too generic to be right. I suggest you look up the AWS Beanstalk All Applications screen. In the box that appears on the right for the correct environment you will find your URL which will be something like this

https://test-env.asu2mcXXrr.eu-west-2.elasticbeanstalk.com

@michal9225 what you have to just set is the Routing. What happens is beanstalk URL expect that your application is running on Port 80 and while developing an application in our local system we generally change the port as our other application or services may be running on most common ports.

So now you have two options:-

1- set a load balancer and route 5000 port to 80 and then access the application via load balancer URL

2- change the port from 5000 to 80 from your Application.property file (server.port = 80)

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