使用AWS Elastic Beanstalk进行deploing时,Spring启动webapp会失败 - jpa配置?

时间:2018-05-26 20:04:46

标签: hibernate amazon-web-services spring-boot jpa elastic-beanstalk

我有一个在本地工作正常的Spring Web应用程序。 我在RDS上有我的MySQL数据库,我还在S3存储桶中存储了一些图像。 然后我尝试使用Elastic Beanstalk部署War,当我输入URL时,我得到的唯一一件事是404错误。

然后我去查看日志,我认为这是造成问题的原因:

javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution

所以我认为我的数据源配置存在问题,但实际上找不到解决方案。

这是我的application.properties:

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto = update
spring.datasource.url = jdbc:mysql://mysql-instance.rrgatg5flqq6.us-east-2.rds.amazonaws.com:3306/mydb
spring.datasource.username = ****
spring.datasource.password = ****
spring.datasource.driver-class-name = com.mysql.jdbc.Driver

这是pom.xml:

<groupId>com.spring</groupId>
<artifactId>gabphoto</artifactId>
<version>1.0</version>
<packaging>war</packaging>

<name>gabphoto</name>
<description>Exam project 5 sem</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.1.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>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
        <version>1.11.133</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

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

先谢谢你们!

1 个答案:

答案 0 :(得分:0)

使用此Technologi堆栈遇到类似的错误:弹性beantalk-RDS-spring boot-postgresql。

此错误可能导致任何问题,其中一些问题,请检查RDS安全组> Inboud>编辑>在源列中选择任何地方。请尝试这种情况,以确保您可以访问数据库。可以帮助您...

RDS security group inbound > choose source anywhere