您在范围内没有隐式应用程序:带有Oracle的PlayFramework [英] You do not have an implicit Application in scope: PlayFramework with Oracle

查看:42
本文介绍了您在范围内没有隐式应用程序:带有Oracle的PlayFramework的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用播放框架访问oracle数据源时出现以下错误:

Getting following error when trying to access oracle DataSource using play framework:

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:

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如下:

Controller Application.scala is as follows:

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") } 

}

是什么导致此问题.一切对我来说都是正确的.

What is causing this issue. Everything looks correct to me.

仅供参考.玩! 2.1.4(使用Java 1.6.0_24和Scala 2.10.0)

-谢谢

推荐答案

错误消息实际上告诉您该怎么做:您在范围内没有隐式的Application.如果要将当前运行的应用程序置于上下文中,只需添加导入play.api.Play.current .

The error message is actually telling you what to do: 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.

import play.api.Play.current

这是getDataSource方法的样子:

This is what the getDataSource method look like:

  def getDataSource(name: String = "default")(implicit app: Application): DataSource = app.plugin[DBPlugin].map(_.api.getDataSource(name)).getOrElse(error)

如您所见,它在第二个参数列表中包含一个隐式应用程序,并且编译器正在寻找一个可以在导入中找到的隐式声明的应用程序.

As you can see it takes an implicit Application in the second argument list and the compiler is looking for an implicitly declared Application which can be found in the import.

这篇关于您在范围内没有隐式应用程序:带有Oracle的PlayFramework的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆