Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database 如果我们使用特定的数据源,如何在Play框架(Scala,I)中注入数据库?_Database_Dependency Injection_Playframework_Scaldi - Fatal编程技术网

Database 如果我们使用特定的数据源,如何在Play框架(Scala,I)中注入数据库?

Database 如果我们使用特定的数据源,如何在Play框架(Scala,I)中注入数据库?,database,dependency-injection,playframework,scaldi,Database,Dependency Injection,Playframework,Scaldi,我想在我的play framework项目中使用Anorm作为DB库,使用BushTi作为DI。但现在我无法注入数据库,因为在最新的play framwork中,我们不能再使用DB.getConnection(“数据源”) 你们中有谁能解释一下如何将NamedDatabase转换到Shorti环境 顺便说一句,我的代码是如何在scala游戏中使用NamedDatabase class MembershipSqlStorage @Inject() (@NamedDatabase("membersh

我想在我的play framework项目中使用Anorm作为DB库,使用BushTi作为DI。但现在我无法注入数据库,因为在最新的play framwork中,我们不能再使用DB.getConnection(“数据源”)

你们中有谁能解释一下如何将NamedDatabase转换到Shorti环境

顺便说一句,我的代码是如何在scala游戏中使用NamedDatabase

class MembershipSqlStorage @Inject() (@NamedDatabase("membership") db: Database)
它是有效的


谢谢

PlayFramework为Anorm DB库提供了有用的文档

你可以参考:

您需要将Anorm和JDBC插件添加到您的依赖项中:

libraryDependencies++=Seq( jdbc, “com.typesafe.play”%%“anorm”%%“2.5.1” )

首先,

“进口阿诺姆”

然后简单地使用SQL对象创建查询。您需要一个连接来运行查询,并且可以在DI的帮助下从play.api.db.db助手中检索一个连接

database.withConnection{implicit c=>

val结果:Boolean=SQL(“选择1”).execute()

}

要在play应用程序中添加Built i支持,您需要在build.sbt中包含Built i play:

libraryDependencies+=“org.sporthi”%%“sporthi播放”%%“0.5.15”


也解决了
lazy val database=inject[DBApi].database(“membership”)
虽然这在理论上可以回答这个问题,但在这里包括答案的基本部分,并提供链接供参考。