gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 20:17:49 25 4
gpt4 key购买 nike

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

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

.properties 文件

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

jdbc.password=admin
jdbc.username=admin

Spring .xml

<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>com\cts\resource\constant.properties</value>
</property>
</bean>

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>

<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>

非常感谢对此的任何帮助,我只是因为这个奇怪的错误而无法取得进展。

最佳答案

我认为问题可能是 postgres 数据库配置为允许使用 md5 散列的唯一密码。

您可以通过转到配置文件 pg_hba.conf 来检查这是否属实。使用以下属性搜索 host all all all 如果您发现该属性配置如下:

host all all all md5

问题是您需要将密码散列为 md5。您可以通过将配置更改为:

  • trust 而不是 md5 -> 将允许用户无需任何密码即可连接
  • password 而不是 md5 -> 将允许用户使用纯文本密码进行连接

关于java - 由 : org. postgresql.util.PSQLException 引起:致命:用户 "admin"的密码验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38427407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com