Play Framework - ExecutionContext cannot be resolved when trying to match a promise

WS.url("https://api.humanapi.co/v1/human"+url+"?updated_since="+updatedSince).setHeader("Authorization", "Bearer "+accessToken) .setHeader("Accept", "application/json").get().map( new Function<WSResponse, JsonNode>() { public JsonNode apply(WSResponse response) { JsonNode json = response.asJson(); success(json); return json; } } ); 

The error message "The type scala.concurrent.ExecutionContext cannot be resolved will appear. It indirectly refers to the required .class files.

I tried adding

 import scala.concurrent.ExecutionContext; 

but then the error simply β€œmoves” from the line where the promise is at the top of the file and still will not compile.

I also tried adding

 import play.api.libs.concurrent.Execution.Implicit.defaultContext; 

but there is no such thing to import.

The playback platform used is 2.4.2.

SBT file:

 version := "1.0-SNAPSHOT" lazy val root = (project in file(".")).enablePlugins(PlayJava) scalaVersion := "2.11.6" resolvers ++= Seq( "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/", "sonatype snapshots" at "https://oss.sonatype.org/content/repositories/releases/" ) checksums := Nil libraryDependencies ++= Seq( javaJdbc, cache, javaWs, "org.mockito" % "mockito-all" % "1.10.19", "commons-codec" % "commons-codec" % "1.10", "de.flapdoodle.embed" % "de.flapdoodle.embed.mongo" % "1.48.0", "org.mongodb.morphia" % "morphia" % "1.0.0-rc0" ) libraryDependencies += "org.mongodb" % "mongodb-driver" % "3.0.2" // Play provides two styles of routers, one expects its actions to be injected, the // other, legacy style, accesses its actions statically. routesGenerator := InjectedRoutesGenerator 
+6
source share
4 answers

I had the same problem and realized that my setup of Play Eclipse was incomplete (I skipped steps 2 and 3 below). I repeated the setup, this time after all the appropriate steps. ExecutionContext became solvable then.

Eclipse Setup Instructions

Original link: https://www.playframework.com/documentation/2.4.x/IDE

Updated link: https://www.playframework.com/documentation/2.5.x/IDE

1) Add this line to project / plugins.sbt:

 addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0") 

2) Add this line to build.sbt:

 EclipseKeys.preTasks := Seq(compile in Compile) 

3) Add these lines to build.sbt (if you don't have Scala sources):

 EclipseKeys.projectFlavor := EclipseProjectFlavor.Java // Java project. Don't expect Scala IDE EclipseKeys.createSrc := EclipseCreateSrc.ValueSet(EclipseCreateSrc.ManagedClasses, EclipseCreateSrc.ManagedResources) // Use .class files instead of generated .scala files for views and routes 

4) Save all project files. Close Eclipse.

5) At the cd command prompt in the project folder and run:

 activator "eclipse with-source=true" 

6) Open Eclipse. Open your project. Update it as follows:

Package Explorer> right-click your_project> refresh icon

+8
source

Just install the ScalaIDE plugin from the Eclipse Marketplace. This solves the + problem, allows you to develop Scala.

+1
source

Decision:

import scala.concurrent.ExecutionContext;

Ignore eclipse errors.

0
source

also try removing the eclipse material from the source directory (.project, .classpath, etc.) and re-import the project.

0
source

All Articles