You have no implicit application in scope: PlayFramework with Oracle

Getting the following error while trying to access Oracle DataSource using the playback frame:

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" 

The Application.scala controller looks like this:

 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 the cause of this problem. Everything looks right to me.

Fyi. play! 2.1.4 (using Java 1.6.0_24 and Scala 2.10.0)

-Thanks

+7
oracle scala playframework
source share
1 answer

The error message actually tells you what to do: you do not have an implicit application in the scope. If you want to bring the currently running application into context, just add import play.api.Play.current.

 import play.api.Play.current 

Here's what the getDataSource method looks 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 list of arguments, and the compiler looks for the implicitly declared application that can be found in the import.

+19
source share

All Articles