Lagom应用使用PostgreSQL作为持久化数据库报错求助
That error happens because Akka Persistence JDBC defaults to looking for a JNDI datasource named DefaultDB, but your setup uses a HikariCP-backed JDBC connection defined in application.conf. You just need to adjust your config to tell Akka Persistence to use your configured database instead of relying on JNDI.
Here's what you need to do to fix this:
1. Update application.conf to point Akka Persistence to your database
Add these settings to your config file to override the default JNDI lookup behavior:
akka.persistence.jdbc { journal { slick { db = "db.default" } } snapshot-store { slick { db = "db.default" } } }
This tells both the event journal and snapshot store for Akka Persistence to use the db.default PostgreSQL database you've already set up.
2. Complete your database configuration with credentials and pool settings
You should also add your PostgreSQL username, password, and optional HikariCP pool settings to ensure the connection works properly (replace the placeholders with your actual database credentials):
db.default { driver = "org.postgresql.Driver" url = "jdbc:postgresql://localhost:5432/postgres" username = "your_postgres_username" password = "your_postgres_password" hikaricp { maximum-pool-size = 10 connection-timeout = 30000 } }
3. Verify your Application class components
Make sure your Lagom application class mixes in all required components. You should have at least:
class YourApplication(context: LagomApplicationContext) extends LagomApplication(context) with JdbcPersistenceComponents with HikariCPComponents with SlickPersistenceComponents { // Your service bindings and other application logic here }
The SlickPersistenceComponents ensures Slick integrates correctly with your JDBC setup.
Final Pre-Restart Checks
Before firing up your app again:
- Confirm PostgreSQL is running on
localhost:5432 - Verify the
postgresdatabase exists (or update the database name in your URL if you're using a custom one) - Ensure your database user has read/write permissions for the target database
After making these changes, the "DefaultDB not found" error should be resolved, and your Lagom entities will be able to persist data to PostgreSQL as expected.
内容的提问来源于stack exchange,提问作者Suraj Gharat

