How to deploy a Spring Boot application with custom .properties files to AWS ElasticBeanstalk?

tambovflow :

I have a Spring Boot application that uses different environment properties. Based on the selected environment it fetches the needed data from the application-{dev/stag/prod}.properties file which is located in ./resources. Everything works like it should when running locally via InteliJ and also when running the created .jar file (created using Gradle with bootJar).

I've created a AWS ElasticBeanstalk application. Within that application I created a Java environment and deployed the .jar file there. When deploying I see the following errors in the logs:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.5.RELEASE)

2019-07-12 07:47:26.773  INFO 3315 --- [           main] nl.abc.sgapi.SgApiApplication      : Starting SgApiApplication on ip-172-31-29-160 with PID 3315 (/var/app/current/application.jar started by webapp in /var/app/current)
2019-07-12 07:47:26.795  INFO 3315 --- [           main] nl.abc.sgapi.SgApiApplication      : The following profiles are active: dev
2019-07-12 07:47:31.392  INFO 3315 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-07-12 07:47:31.713  INFO 3315 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 301ms. Found 6 repository interfaces.
2019-07-12 07:47:33.384  INFO 3315 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$59ac5acc] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-07-12 07:47:33.518  INFO 3315 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.throttling-com.weddini.throttling.autoconfigure.ThrottlingProperties' of type [com.weddini.throttling.autoconfigure.ThrottlingProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-07-12 07:47:33.530  INFO 3315 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'com.weddini.throttling.autoconfigure.ThrottlingAutoConfiguration' of type [com.weddini.throttling.autoconfigure.ThrottlingAutoConfiguration$$EnhancerBySpringCGLIB$$16a02498] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-07-12 07:47:33.543  INFO 3315 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'throttlingEvaluator' of type [com.weddini.throttling.service.ThrottlingEvaluatorImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-07-12 07:47:33.569  INFO 3315 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'throttlingService' of type [com.weddini.throttling.service.ThrottlingServiceImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-07-12 07:47:33.593  INFO 3315 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.hateoas.config.HateoasConfiguration' of type [org.springframework.hateoas.config.HateoasConfiguration$$EnhancerBySpringCGLIB$$d92ca7fe] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-07-12 07:47:35.100  INFO 3315 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 5000 (http)
2019-07-12 07:47:35.224  INFO 3315 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-07-12 07:47:35.225  INFO 3315 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.19]
2019-07-12 07:47:35.515  INFO 3315 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-07-12 07:47:35.516  INFO 3315 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 8443 ms
2019-07-12 07:47:39.298  INFO 3315 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2019-07-12 07:47:50.424 ERROR 3315 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.

org.postgresql.util.PSQLException: The connection attempt failed.
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:292) ~[postgresql-42.2.5.jar!/:42.2.5]
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.2.5.jar!/:42.2.5]
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195) ~[postgresql-42.2.5.jar!/:42.2.5]
    at org.postgresql.Driver.makeConnection(Driver.java:454) ~[postgresql-42.2.5.jar!/:42.2.5]
    at org.postgresql.Driver.connect(Driver.java:256) ~[postgresql-42.2.5.jar!/:42.2.5]
    at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136) ~[HikariCP-3.2.0.jar!/:na]

It seems as if AWS ElasticBeanstalk is not able to read the values in the application-dev.properties file.

Here's what my application-dev.properties file looks like:

spring.datasource.hikari.connectionTimeout=20000
spring.datasource.hikari.maximumPoolSize=5
spring.datasource.url=jdbc:postgresql://{REDACTED}
spring.datasource.username={REDACTED}
spring.datasource.password={REDACTED}
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
app.message=Hello from dev properties

I've tried moving the environment specific properties to the main application.properties file and create a .jar. But this did not work either.

What can I try next?

narzero :

It looks like your Spring Boot application can't connect to the PostgreSQL database. I would suggest you dubbel check the username and password. And if you have firewall active, check if the server that has to connect to the database is whitelisted.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=122127&siteId=1