Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

You do not have an implicit Application in scope: PlayFramework with 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:

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 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.

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

-Thanks

like image 804
user204069 Avatar asked Sep 16 '13 18:09

user204069


People also ask

How do you implement an implicit transaction in Java?

Implementing an Implicit Transaction using Transaction Scope. The TransactionScope class provides a simple way to mark a block of code as participating in a transaction, without requiring you to interact with the transaction itself. A transaction scope can select and manage the ambient transaction automatically.

What is the difference between scope3 and scope4?

Note that scope3 is the root scope of a new transaction, and that scope4 has no ambient transaction. Although the default and most commonly used value of TransactionScopeOption is Required, each of the other values has its unique purpose.

What happens when a scope is instantiated with suppress?

If the scope is instantiated with Suppress, it never takes part in a transaction, regardless of whether an ambient transaction is present. A scope instantiated with this value always have null as its ambient transaction. The above options are summarized in the following table.

Do nested scopes affect the root scope of a transaction?

Only if all the scopes from the root scope down to the last nested scope vote to commit the transaction, will the transaction be committed. Not calling Complete in a nested scope will affect the root scope as the ambient transaction will immediately be aborted.


Video Answer


1 Answers

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

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.

like image 127
maba Avatar answered Oct 05 '22 15:10

maba