尝试使用play框架访问oracle DataSource时出现以下错误:
sbt.PlayExceptions$CompilationException: Compilation error[You do not have an implicit Application in scope. If you want to bring the current running Application into context,just add import play.api.Play.current]
build.properties:
sbt.version=0.12.2 db.default.driver=oracle.jdbc.driver.OracleDriver db.default.url="jdbc:oracle:thin:@(.....basic))))" db.default.user="username" db.default.pass="passowrd"
Controller Application.scala如下:
package controllers import play.api._ import play.api.mvc._ import play.api.db._ object Application extends Controller { val d = DB.getDataSource(); def index = Action { request => Ok("something") } }
是什么导致了这个问题.一切看起来都对我不对.
仅供参考.玩! 2.1.4(使用Java 1.6.0_24和Scala 2.10.0)
-谢谢
错误消息实际上是在告诉您该怎么做:您在范围内没有隐式应用程序.如果要将当前运行的Application引入上下文,只需添加import play.api.Play.current.
import play.api.Play.current
这就是getDataSource方法的样子:
def getDataSource(name: String = "default")(implicit app: Application): DataSource = app.plugin[DBPlugin].map(_.api.getDataSource(name)).getOrElse(error)
正如您所看到的,它在第二个参数列表中采用了一个隐式Application,并且编译器正在查找可以在导入中找到的隐式声明的Application.