You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PlayFramework Slick应用连接Docker PostgreSQL数据库报错求助

问题修复方案

你的配置存在两处关键错误,导致数据库连接失败:

1. 错误使用了H2数据库的驱动与Slick Profile

你的应用配置里指定了H2的驱动和Profile,但实际要连接PostgreSQL,必须切换为对应PostgreSQL的配置项:

  • Slick Profile需改为 slick.jdbc.PostgresProfile$
  • JDBC驱动需改为 org.postgresql.Driver

2. JDBC URL格式错误

原URL jdbc:postgresql://localhost:5432/postgressslmode=require 有两个问题:

  • 数据库名和参数之间缺少 ? 分隔符
  • 数据库名与参数拼接错误(默认数据库名为postgres,参数需通过?追加)

正确的URL格式应为:jdbc:postgresql://localhost:5432/postgres?sslmode=require

修正后的完整应用配置

slick.dbs.default.profile="slick.jdbc.PostgresProfile$"
slick.dbs.default.db.driver="org.postgresql.Driver"
slick.dbs.default.db.url="jdbc:postgresql://localhost:5432/postgres?sslmode=require"
slick.dbs.default.db.user="postgres"
slick.dbs.default.db.password="admin"

额外检查项

  • 确保项目依赖已添加PostgreSQL JDBC驱动和Slick的PostgreSQL支持库,例如在build.sbt中添加:
libraryDependencies += "org.postgresql" % "postgresql" % "42.6.0"
libraryDependencies += "com.typesafe.slick" %% "slick" % "3.4.1"
libraryDependencies += "com.typesafe.slick" %% "slick-hikaricp" % "3.4.1"
  • 确认Docker容器内PostgreSQL已正常启动,端口映射5432:5432生效,可通过以下命令测试连接:
psql -h localhost -p 5432 -U postgres -d postgres

内容的提问来源于stack exchange,提问作者DevyDev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 09:21:10