0

I am trying to set up a Spring Boot application. Currently I am working in a local environment and I have a Heroku PostgreSQL db. When I start my application it starts with error:

HikariPool-1 - Exception during pool initialization.
org.postgresql.util.PSQLException: El intento de conexión falló.
...
Caused by: java.net.UnknownHostException: @host
...
HHH000342: Could not obtain connection to query metadata

Where I have added the correct hostname and hideen it for security. I know this hostname is right since I've managed to connect using an Express app.

My POM.xml has the following dependencies:}

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>
    
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>
    
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

And my application.properties file is:

spring.datasource.url=jdbc:postgresql://@host:5432/dal2fiqv9or5eg?user=----&password=----&sslmode=require
spring.datasource.username=----
spring.datasource.password=----
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa-hibernate.ddl-auto=create-drop
spring.jpa.show=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_sql=true

Whre once again I hid the host, username and pwd.

After this the application starts.

1 Answer 1

1

The spring.datasource.url property in your application.properties seems to be incorrect.

This file has worked for me:

    #postgres parameters
spring.datasource.url=jdbc:postgresql://<host>:<port>/<database>
spring.datasource.username=<user>
spring.datasource.password=<password>
spring.jpa.show-sql=true

## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update

logging.level.org.springframework=TRACE

logging.level.org.hibernate.type=TRACE
server.port=${PORT:8080}

The values for port, host, database, user, and password can be derived from the HerokuPostgres addon you add to your Heroku app

enter image description here

Do not add @ or any special symobols. Simply replace the values with the values you see in Heroku. eg: spring.datasource.url=jdbc:postgresql://myhostname:5432/mydbname

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks mnagdev! The issue was the @ symbol. Removing it did the work. Maybe you already answered this, but when I deploy this into Heroku, instead of hardcoding values is it posible to use the <host>:<port> syntax? Or should I set environment variables with the heroku CLI?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.