简体   繁体   中英

Deploy Spring Boot application on AWS (Elastic Beanstalk) that uses RDS - Application does not start

I have a SpringBoot application connected to a MySQL database. This has already been installed on AWS and entered into Spring's properties file. The connection works and I can also connect to it with my workbench. But my problem is that the application does not run on AWS. I changed the SERVER_PORT to 5000 (also in the properties) but I can't get the APP to run

The AWS log file:

在此处输入图像描述

在此处输入图像描述

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.6</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.backend</groupId>
<artifactId>SYFALL</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SYFALL</name>
<description>Demo project for Spring Boot</description>
<properties>
    <java.version>11</java.version>
</properties>
<dependencies>

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

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc -->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
</dependencies>

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

</project>

application.properties file:

server.port = 5000
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB

spring.datasource.url = jdbc:mysql://AWS_DATABASE:3306/syfall
spring.datasource.username = xxx
spring.datasource.password = xxx

## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect

# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update

The application was built as a JAR file.

As stated in the comments, I have my sample Spring BOOT app that uses MySQL RDS data and queries and displays data perfectly.

在此处输入图像描述

I am currently in the process of deploying to Elastic Beanstalk. I will update this thread with notes once done.

UPDATE

I successfully deployed this Spring BOOT app to Elastic Beanstalk and got the RDS Connection working. I packaged up the Spring BOOT app into a JAR by using mvn package . Then I deployed the JAR onto Elastic Beanstalk.

在此处输入图像描述

Notes:

Be sure to specify your environment variables correctly in the Elastic Beanstalk environment (as opposed to a Spring config file) -- as shown here:

在此处输入图像描述

The AWS Creds are needed if your app uses an AWS Service Client. I use SES in this app so I need them

Now here is the important part. You need to set the Inbound rules so that a connection from the app deployed on EB to RDS can be made. I simply used this for testing....

在此处输入图像描述

To take this further, you can of course use the IP Address of your app on Beanstalk in your Inbound Rule. To do so, get the IP of your Elastic Beanstalk app. Then use that IP in your inbound rule.

在此处输入图像描述

Make sure that the Security Group your RDS uses is also the same Security Group your EB app uses. Both RDS and EB has to be in same region.

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