【发布时间】:2020-01-24 13:10:04
【问题描述】:
运行时出现此错误
$ mvn clean install
org.postgresql.util.PSQLException: Connection to localhost:5432
refused. Check that the hostname and port are correct and that the
postmaster is accepting TCP/IP connections.
然而,在我的 application.properties 上,我已明确将端口定义为 5433:
spring.datasource.url=jdbc:postgresql://localhost:5433/mydb
我还在 postgres.conf 中所述的端口 5433 上运行 postgres:
port = 5433 # (change requires restart)
我确实跑了
$ systemctl postgresql restart
更改端口后。
这里有什么问题? 我没有在项目文件的其他任何地方定义端口。
完整的 application.properties 文件:
spring.main.banner-mode=off
logging.level.org.springframework=ERROR
spring.jpa.hibernate.ddl-auto=none
spring.datasource.initialization-mode=always
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://localhost:5433/mydb
spring.datasource.username=myuser
spring.datasource.password=mypass
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.profiles.active=@spring.profiles.active@
【问题讨论】:
-
很明显你的应用没有使用你认为应该使用的配置
-
我确信在 spring-boot 项目中,除了 application.properties 文件之外,没有其他地方可以为 postgres 设置端口。我唯一能想到的是,该值存储在以前运行的某个位置。
-
附带说明:为什么您的构建过程需要 Spring 来连接 DBMS?
-
@Amadán 我不明白你的问题。我有一个 springboot 项目,我使用 postgres db 来保存体育赛事分数。在构建过程中我无法连接到它,因为 maven build 使用了我定义的不同端口。
-
你能添加你的 pom.xml 吗?
标签: java spring postgresql maven