I have a simple spring boot project using spring-boot-starter-data-jpa. The application is running fine in my local. But when I deploy the application to AWS using Elastic Bean stalk, its giving the below error:
web: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment].
I guess something related to packaging the jar, but couldn't find the solution. Please help.
Full log:
Mar 14 10:46:02 ip-172-31-11-21 web: ... 57 common frames omitted Mar 14 10:46:02 ip-172-31-11-21 web: Caused by: java.net.ConnectException: Connection refused (Connection refused) Mar 14 10:46:02 ip-172-31-11-21 web: at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na] Mar 14 10:46:02 ip-172-31-11-21 web: at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412) ~[na:na] Mar 14 10:46:02 ip-172-31-11-21 web: at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255) ~[na:na] Mar 14 10:46:02 ip-172-31-11-21 web: at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237) ~[na:na] Mar 14 10:46:02 ip-172-31-11-21 web: at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:na] Mar 14 10:46:02 ip-172-31-11-21 web: at java.base/java.net.Socket.connect(Socket.java:609) ~[na:na] Mar 14 10:46:02 ip-172-31-11-21 web: at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:156) ~[mysql-connector-java-8.0.28.jar!/:8.0.28] Mar 14 10:46:02 ip-172-31-11-21 web: at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:63) ~[mysql-connector-java-8.0.28.jar!/:8.0.28] Mar 14 10:46:02 ip-172-31-11-21 web: ... 60 common frames omitted Mar 14 10:46:02 ip-172-31-11-21 web: 2022-03-14 10:46:02.009 ERROR 8587 --- [ main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] Mar 14 10:46:02 ip-172-31-11-21 web: 2022-03-14 10:46:02.009 WARN 8587 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] Mar 14 10:46:02 ip-172-31-11-21 web: 2022-03-14 10:46:02.034 INFO 8587 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] Mar 14 10:46:02 ip-172-31-11-21 web: 2022-03-14 10:46:02.094 INFO 8587 --- [ main] ConditionEvaluationReportLoggingListener : Mar 14 10:46:02 ip-172-31-11-21 web: Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. Mar 14 10:46:02 ip-172-31-11-21 web: 2022-03-14 10:46:02.147 ERROR 8587 --- [ main] o.s.boot.SpringApplication : Application run failed Mar 14 10:46:02 ip-172-31-11-21 web: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] Mar 14 10:46:02 ip-172-31-11-21 web: at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.15.jar!/:5.3.15]
It got resolved after I changed the inbound rules for the security group tagged to the RDS database.