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

Lagom应用使用PostgreSQL作为持久化数据库报错求助

Fixing "DefaultDB not found" Error When Using PostgreSQL with Lagom Persistence

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 postgres database 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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 00:38:12