引起:org.postgresql.util.PSQLException:致命:用户密码验证失败" admin"

时间:2016-07-18 01:16:00

标签: java spring postgresql jdbc

当我尝试使用我的凭据(pgadmin iii - postgres sqltool)连接到我的PostgreSQL服务器时,它工作正常。当我尝试从我的Java应用程序连接时,我得到以下日志。这很奇怪

file_get_contents('php://input');

.properties文件

org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is org.postgresql.util.PSQLException: FATAL: password authentication failed for user "admin"
    at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:240)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy8.getCollegeDetails(Unknown Source)
    at com.cts.bo.HESBO.registerCourse(HESBO.java:42)
    at com.cts.facade.HESFacade.registerCourse(HESFacade.java:34)
    at com.cts.manager.HESManager.registerCourse(HESManager.java:34)
    at com.cts.presentation.Tester.registerCourse(Tester.java:66)
    at com.cts.presentation.Tester.main(Tester.java:159)
**Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "admin"**
    at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:415)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:188)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
    at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:143)
    at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:29)
    at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:21)
    at org.postgresql.jdbc3g.Jdbc3gConnection.<init>(Jdbc3gConnection.java:24)
    at org.postgresql.Driver.makeConnection(Driver.java:412)
    at org.postgresql.Driver.connect(Driver.java:280)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:164)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:149)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119)
    at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:202)
    ... 11 more

spring.xml

jdbc.driverClassName=org.postgresql.Driver
jdbc.url=jdbc:postgresql://localhost:5432/postgres

jdbc.password=admin
jdbc.username=admin

对此的任何帮助都非常感谢,因为这个奇怪的错误,我无法进步。

1 个答案:

答案 0 :(得分:3)

如果您还没有尝试过,请查看您的pg_hba.conf文件。它将被命名为

/etc/postgresql/9.6/main/pg_hba.conf (Ubuntu 16.04)
/var/lib/pgsql/9.3/data/pg_hba.conf (Fedora 20);

您可能必须使用find / -name pg_hba.conf来定位它。

在文件的底部,将METHOD值更改为信任以进行本地测试(有关完整信息,请参阅postgres文档)。重新启动postgres以确保所有内容都已清理干净并读取新的参数:

sudo systemctl restart postgresql     # ubuntu

希望这能够治愈你的困境。它解决了我在Ubuntu / Fedora上的问题。