【问题标题】:spring jpa connect failed to postgres serverspring jpa 连接到 postgres 服务器失败
【发布时间】:2022-02-21 14:23:14
【问题描述】:

我创建了 spring 项目来对 postgres 数据库服务器进行 CRUD,但出现了一些错误。

HHH000342:无法获得查询元数据的连接

org.postgresql.util.PSQLException:连接尝试失败。 在 org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:313) ~[postgresql-42.3.1.jar:42.3.1] 在 org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51) ~[postgresql-42.3.1.jar:42.3.1] 在 org.postgresql.jdbc.PgConnection.(PgConnection.java:225) ~[postgresql-42.3.1.jar:42.3.1] 在 org.postgresql.Driver.makeConnection(Driver.java:466) ~[postgresql-42.3.1.jar:42.3.1] 在 org.postgresql.Driver.connect(Driver.java:265) ~[postgresql-42.3.1.jar:42.3.1] 在 com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-4.0.3.jar:na]

这是我的 application.properties

spring.datasource.url=jdbc:postgresql://3.1.84.18:5432/postgres

spring.datasource.username=postgres

spring.datasource.password=postgres

spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect

spring.jpa.hibernate.ddl-auto=none spring.jpa.show-sql=true

spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

我的 pom.xml

enter image description here

【问题讨论】:

  • 谢谢,在文件 pg_hba.config 中我们更新了“host all all 0.0.0.0/0 md5”。我从 ident 改成了 md5 认证方式,成功了!
  • 将 (XML) 代码发布为图像。请参阅此处了解更多详细信息原因:meta.stackoverflow.com/questions/285551

标签: postgresql jpa


【解决方案1】:

你的 pom.xml 是正确的

<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <scope>runtime</scope>
</dependency>

创建postgre用户后必须有密码,然后再创建postgre数据库

在你的 application.properties 上,你可以使用用他的密码创建的用户

spring.datasource.database-platform=org.hibernate.dialect.PostgreSQLDialect 
spring.datasource.url=jdbc:postgresql://localhost:5432/database_name
spring.datasource.username=user_name
spring.datasource.password=user_password
spring.jpa.hibernate.ddl-auto=update

【讨论】:

  • 我的问题是,在尝试解决“未连接到数据库”之后,我将 pg_hba.conf 更改为 host all all 0.0.0.0/0 ident 我们重试 host all all 0.0.0.0/ 0 md5,问题已解决。谢谢
【解决方案2】:

我的问题是,在尝试解决“未连接到数据库”之后,我将 pg_hba.conf 更改为 host all all 0.0.0.0/0 ident 我们重试 host all all 0.0。 0.0/0 md5, 问题得到解决。

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-09
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多