【问题标题】:Injecting a JDBC Database connection in a Play for Scala standalone application在 Play for Scala 独立应用程序中注入 JDBC 数据库连接
【发布时间】:2017-04-09 21:20:28
【问题描述】:

我在 Play for Scala 中注入 JDBC Database Connections 以在 Web 应用程序中作为 explained here 使用:

这是我使用的声明:

class ScalaControllerInject @Inject()(db: Database) extends Controller {

    // rest of the code...

我需要在 独立 Play for Scala 应用程序中注入 JDBC 数据库连接(即没有控制器),如下所示:

object Main extends App {

    val db: Database  = // ... get database 
    val conn = db.getConnection()

    // .... rest of the code
}

这可能吗?

【问题讨论】:

    标签: scala playframework playframework-2.0


    【解决方案1】:

    您可以只创建一个(Postgres 示例):

    val dbUrl = "jdbc:postgresql://localhost:5432/databaseName?user=username&password=yourpassword"
    val database = Databases("org.postgresql.Driver",dbUrl,"testingzzz")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-13
      • 1970-01-01
      • 1970-01-01
      • 2010-09-12
      • 1970-01-01
      相关资源
      最近更新 更多