使用Play-2.6与Quill.io时加载数据源失败问题求助
Hey there! Since you and your team are new to Play and Scala, let's walk through the most likely causes for this error—no need to stress about the question being "too basic"—we've all been there!
First, let's start with the most common pitfalls:
1. Incomplete or Incorrect Database URL in application.conf
Play relies on the JDBC URL to locate your database, and even small typos can break things. Depending on which database you're using (PostgreSQL/MySQL), double-check your URL format:
- PostgreSQL: Should look like
jdbc:postgresql://localhost:5432/app-users(default port is 5432) - MySQL: Should look like
jdbc:mysql://localhost:3306/app-users?useSSL=false&serverTimezone=UTC(default port is 3306; the extra params fix common 8.x connector issues)
Since your root user has no password, make sure you either:
- Omit the password parameter entirely, or
- Explicitly set it to an empty string in the URL or separate config line (some drivers require this to avoid confusion).
2. Missing Database Driver Dependency
Play doesn't include JDBC drivers out of the box—you need to add the correct one to your build.sbt file:
- PostgreSQL:
libraryDependencies += "org.postgresql" % "postgresql" % "42.6.0" - MySQL:
libraryDependencies += "mysql" % "mysql-connector-java" % "8.0.33"
Make sure the driver version matches your database version (e.g., MySQL 8.x needs connector 8.x, not 5.x).
3. Incomplete Database Config in application.conf
Don't forget to define all required database settings! Here's a complete example for PostgreSQL (adjust driver for MySQL):
db.default.driver = org.postgresql.Driver db.default.url = "jdbc:postgresql://localhost:5432/app-users" db.default.user = root db.default.password = "" # Critical for no-password users—some drivers won't assume empty
The driver line is easy to overlook, but Play needs it to know which JDBC implementation to use.
4. User Connection Permissions (Even for Root!)
Just because you created the database as root doesn't mean root can connect via JDBC.
- PostgreSQL: Check your
pg_hba.conffile (usually in/var/lib/postgresql/<version>/main/on Linux) to ensure there's a line allowing root from localhost with trust authentication (since no password):
After editing, restart PostgreSQL for changes to take effect.local all root trust host all root 127.0.0.1/32 trust - MySQL: Verify root's host access with this query:
If root's host isSELECT user, host FROM mysql.user WHERE user='root';localhost, you're good for local connections. If it's restricted to another host, update it withALTER USER 'root'@'localhost' IDENTIFIED BY '';(to ensure empty password is set correctly).
5. Database Service Isn't Running
Double-check that your database server is actually up and running!
- Linux: Use
systemctl status postgresqlorsystemctl status mysql - Windows: Check the Services list for PostgreSQL/MySQL and confirm it's started.
Quick Pre-Play Test
Before debugging Play further, try connecting to the database manually using the command line:
- PostgreSQL:
psql -U root app-users - MySQL:
mysql -u root app-users
If this fails, fix the database connection issue first—Play can't connect if even the command line can't!
内容的提问来源于stack exchange,提问作者jmkoni

