javaspringpostgresqlspring-boot

Java Springboot application returning password authentication failed for user "postgres"


I am trying to develop a web app using spring boot and postgres. I used http://start.spring.io/ to create a starter spring project with Postgres SQL jdbc driver as a dependency. I have added the following in application.properties file

spring.datasource.url= jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=postgres
spring.datasource.password="mypassword@123"   
spring.jpa.hibernate.ddl-auto=validate

However, this is throwing the following error:

2017-07-30 19:09:15.168 ERROR 2959 --- [           main] o.a.tomcat.jdbc.pool.ConnectionPool      : Unable to create initial connections of pool.

org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
    at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:443) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:217) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:215) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
    at org.postgresql.Driver.makeConnection(Driver.java:404) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
    at org.postgresql.Driver.connect(Driver.java:272) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
    at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310) ~[tomcat-jdbc-8.5.16.jar:na]
    at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203) ~[tomcat-jdbc-8.5.16.jar:na]
    at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:735) [tomcat-jdbc-8.5.16.jar:na]
    at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:667) [tomcat-jdbc-8.5.16.jar:na]

The password is not wrong. When I use psql to log in to the database using that password, it works.

The pg_hba.conf file is:

local   all             all                                     password
host    all             all             127.0.0.1/32            password
host    all             all             ::1/128                 password

I'm using java 1.8 with postgres SQL 9.6 on my macbook pro.


Solution

  • Your password should be a simple text (without adding characters as ")

     spring.datasource.password=mypassword