Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ./gradlew -t runPlayBinary
- /Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:4: object inject is not a member of package javax
- import javax.inject._
- ^
- /Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:21: not found: type AbstractController
- class AsyncController @Inject()(cc: ControllerComponents, actorSystem: ActorSystem)(implicit exec: ExecutionContext) extends AbstractController(cc) {
- ^
- /Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:20: trait Singleton is abstract; cannot be instantiated
- @Singleton
- ^
- /Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:21: not found: type ControllerComponents
- class AsyncController @Inject()(cc: ControllerComponents, actorSystem: ActorSystem)(implicit exec: ExecutionContext) extends AbstractController(cc) {
- ^
- /Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:21: not found: type Inject
- class AsyncController @Inject()(cc: ControllerComponents, actorSystem: ActorSystem)(implicit exec: ExecutionContext) extends AbstractController(cc) {
- ^
- /Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:32: not found: value Ok
- getFutureMessage(1.second).map { msg => Ok(msg) }
- build.gradle
- repositories {
- jcenter()
- maven {
- name "typesafe-maven-release"
- url "https://repo.typesafe.com/typesafe/maven-releases"
- }
- ivy {
- name "typesafe-ivy-release"
- url "https://repo.typesafe.com/typesafe/ivy-releases"
- layout "ivy"
- }
- }
- apply plugin: "play"
- apply plugin: "scala"
- apply plugin: "idea"
- model {
- components {
- play {
- platform play: '2.6.6', scala: '2.12'
- injectedRoutesGenerator = true
- }
- }
- }
- idea {
- module {
- sourceDirs += file("app")
- testSourceDirs += file("test")
- scopes.COMPILE = [plus: [configurations.play], minus: []]
- scopes.RUNTIME = [plus: [configurations.playRun], minus: [configurations.play]]
- scopes.TEST = [plus: [configurations.playTest], minus: [configurations.playRun]]
- }
- }
- package controllers
- import akka.actor.ActorSystem
- import javax.inject._
- import play.api._
- import play.api.mvc._
- import scala.concurrent.{ExecutionContext, Future, Promise}
- import scala.concurrent.duration._
- /**
- * This controller creates an `Action` that demonstrates how to write
- * simple asynchronous code in a controller. It uses a timer to
- * asynchronously delay sending a response for 1 second.
- *
- * @param actorSystem We need the `ActorSystem`'s `Scheduler` to
- * run code after a delay.
- * @param exec We need an `ExecutionContext` to execute our
- * asynchronous code.
- */
- @Singleton
- class AsyncController @Inject()(cc: ControllerComponents, actorSystem: ActorSystem)(implicit exec: ExecutionContext) extends AbstractController(cc) {
- /**
- * Create an Action that returns a plain text message after a delay
- * of 1 second.
- *
- * The configuration in the `routes` file means that this method
- * will be called when the application receives a `GET` request with
- * a path of `/message`.
- */
- def message = Action.async {
- getFutureMessage(1.second).map { msg => Ok(msg) }
- }
- private def getFutureMessage(delayTime: FiniteDuration): Future[String] = {
- val promise: Promise[String] = Promise[String]()
- actorSystem.scheduler.scheduleOnce(delayTime) { promise.success("Hi!") }
- promise.future
- }
- }
Add Comment
Please, Sign In to add comment