首页 > 解决方案 > 如何为在 EC2 实例上运行的 Spring Boot 项目配置 AWS RDS?

问题描述

我有一个 AWS EC2 Linux 实例运行我的 Spring Boot 项目中的一个 jar。我创建了一个 AWS RDS Postgres 实例,并尝试从我的 EC2 实例中运行的服务中调用它。我主要遇到配置问题。下面,我尝试在我的 spring application.properties 文件中进行以下配置:

cloud.aws.rds.capstoneinstance
cloud.aws.rds.capstoneinstance.password = mypassword
cloud.aws.rds.capstoneinstance.username = myusername
cloud.aws.rds.capstoneinstance.readReplicaSupport = true
cloud.aws.rds.capstoneinstance.databaseName = mydbname

这是我的 Gradle 导入:

implementation("org.springframework.cloud:spring-cloud-aws-jdbc:2.1.2.RELEASE")

我的程序甚至不会运行,但我相信那只是因为 spring 正在寻找“spring.datasource.url”等。

这是输出:

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

标签: springamazon-web-servicesspring-bootamazon-ec2amazon-rds

解决方案


如果您使用的是 AWS Aurora RDS 集群(Aurora 引擎),而不是直接使用 AWS RDS Postgres(Postgres 引擎),那么 AWS 云驱动程序似乎不支持该功能。

如果此功能对您很重要,请提供更多详细信息。这是他们的路线图很长一段时间。 https://github.com/awspring/spring-cloud-aws/issues/50


推荐阅读