Hello.

I have a Spring Boot application that locally connects to the MySQL database through application.properties as follows:

spring.datasource.url = jdbc:mysql://localhost:3306/dbname spring.datasource.username = someusername spring.datasource.password = somepassword spring.jpa.show-sql = true spring.jpa.hibernate.ddl-auto = update spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect 

Now I am preparing an application to deploy to Amazon. I created a database there. It says here that after creation I received the following environment variables:

RDS_HOSTNAME - The hostname of the DB instance.

RDS_DB_NAME - The database name, ebdb.

RDS_USERNAME - The username that you configured for your database.

RDS_PASSWORD - The password that you configured for your database.

RDS_PORT - This port accepts connections. The default value varies between DB engines.

Question: can I set these variables in my application.properties and limit it to this, or do I need additional settings?

I read a lot about it, but I didn’t find an example of settings with these variables.

I would be very grateful for the example settings.

  • And what's stopping you from trying? ;-) - Slava Semushin
  • I tried, I get the error Caused by: com.mysql.cj.core.exceptions.CJCommunicationsException from Amazon: Communications link failure - Oleg Shankovskyi
  • Attach the updated configs (without passwords / logins, of course) and the full stack-trace, maybe there is something useful there. - Slava Semushin pm

2 answers 2

Try something like

 spring.datasource.username = ${RDS_USERNAME} spring.datasource.password = ${RDS_PASSWORD} 

    @ortex is right, this is exactly what you need to register in the application properties, namely:

     spring.datasource.url = jdbc:postgresql://${RDS_HOSTNAME}:${RDS_PORT}/${RDS_DB_NAME} spring.datasource.username = ${RDS_USERNAME} spring.datasource.password = ${RDS_PASSWORD} 

    At first it didn't work for me, since two more changes had to be made:

    The main class to register in this form:

     @SpringBootApplication public class Application extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(Application.class); } } 

    And also add the following dependency to pom.xml:

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