无法导入play.api.db.databases [英] Unable to import play.api.db.databases
问题描述
我正在Scala Play 2.5.4中开发一个应用程序.我想测试数据库交互,并尝试通过此方法中推荐的方法进行测试.页面.
I am developing an application in Scala Play 2.5.4. I want to test my database interactions, and am attempting to do so by the method recommended in this page.
麻烦是,我无法导入对象play.api.db.Databases.我怀疑我可能需要在build.sbt文件中添加一些内容,但是由于这是Play API的一部分,因此我不确定情况是否如此.
The trouble is, I am unable to import the object play.api.db.Databases. I suspect that I may need to add something to my build.sbt file, but since this is part of the Play API, I'm not so sure that this is the case.
有一些可用的东西,但是API文档中没有显示
There are some things available, but not what is shown in the API doc
推荐答案
是的,您需要在build.sbt
文件中添加以下内容:
Yes, you need to add in your build.sbt
file this:
libraryDependencies += jdbc
然后,重新加载激活器并更新您的依赖项(activator update/sbt update
).
After that, reload activator and update your dependencies (activator update/sbt update
).
请注意,在此之后,您还需要添加要使用的数据库的jdbc驱动程序.在 https://www.playframework.com/documentation/2.5.x/ScalaDatabase中查看更多信息
Note that after this you will need also to add the jdbc driver of the database you intend to use. See more info in https://www.playframework.com/documentation/2.5.x/ScalaDatabase
如评论中所述,这可能会导致Slick问题. 不幸的是,该模块提供了您需要使用的类,因此,如果这导致您遇到问题,则可以尝试两种方法:
As stated in the comments, this may cause problems with Slick. Unfortunately the classes you need to use are provided by that module, so if this causes you problems, you can try two things:
- Extract the class/methods you need and put them in your project: you can get the
Databases
class code in https://github.com/playframework/playframework/blob/2.5.x/framework/src/play-jdbc/src/main/scala/play/api/db/Databases.scala Try to disable the DBModule. I'm not quite sure about the syntax, so try each one of those:
play.modules.enabled -= "play.api.db.DBModule"
play.modules.disabled += "play.api.db.DBModule"
这篇关于无法导入play.api.db.databases的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!