Failing to connect Spring Boot with PostgreSQL with jdbc
Hello all! I am having issues trying to deploy my spring boot project.
Everything works fine on localhost.
The issue seems to be with jdbc when trying to deploy. I made sure to create a postgreSQL project and provide the DATABASE_PRIVATE_URL variable to the spring boot project, and the following is the error message I get through the logs:
ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Failed to determine a suitable driver class
Description:
Failed to configure a DataSource: no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Here it is the section of the properties file that's relevant to the datasource
spring.datasource.url=jdbc:${DATABASE_PRIVATE_URL}
spring.datasource.username=${POSTGRES_USER}
spring.datasource.password=${POSTGRES_PASSWORD}
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
javax.persistence.schema-generation.scripts.action=drop-create
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
server.error.include-message = "always"
spring.jpa.properties.hibernate.jdbc.time_zone=UTC
spring.mvc.format.date-time=iso
spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false
Any help will be really appreciated !
6 Replies
Project ID:
fcc8b408-8ee0-4c61-9fff-e395f93c2d56
Guessing the project ID is the same as Service ID
project ID: fcc8b408-8ee0-4c61-9fff-e395f93c2d56
Just as a side note; I am still under the hobby plan which offers only 512mb of ram, and I can see the build of my app is about 1.1 Gb. Could this issue be somehow related ?
DATABASE_PRIVATE_URL
is not in the correct format that spring expects, please read the spring documentation on how that variable should be formattedthe DATABASE_PRIVATE_URL is a reference variable from a postgreSQL service(id: fcc8b408-8ee0-4c61-9fff-e395f93c2d56),
I didn't format it manually.
I only added the "jdbc" prefix to the DATABASE_PRIVATE_URL to form the url to be used for datasource purposes. it looks like this:
spring.datasource.url=
jdbc:${DATABASE_PRIVATE_URL}
Is there something I am missing ? Again, I didn't manually format the variable, but refered to it.right, it comes with the wrong format, please reference spring's docs for the correct format