Guest User

Untitled

a guest
Oct 22nd, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. ./gradlew -t runPlayBinary
  2.  
  3. /Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:4: object inject is not a member of package javax
  4. import javax.inject._
  5. ^
  6. /Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:21: not found: type AbstractController
  7. class AsyncController @Inject()(cc: ControllerComponents, actorSystem: ActorSystem)(implicit exec: ExecutionContext) extends AbstractController(cc) {
  8. ^
  9. /Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:20: trait Singleton is abstract; cannot be instantiated
  10. @Singleton
  11. ^
  12. /Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:21: not found: type ControllerComponents
  13. class AsyncController @Inject()(cc: ControllerComponents, actorSystem: ActorSystem)(implicit exec: ExecutionContext) extends AbstractController(cc) {
  14. ^
  15. /Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:21: not found: type Inject
  16. class AsyncController @Inject()(cc: ControllerComponents, actorSystem: ActorSystem)(implicit exec: ExecutionContext) extends AbstractController(cc) {
  17. ^
  18. /Users/bobo/scalalab2/play-scala-gradle-template/app/controllers/AsyncController.scala:32: not found: value Ok
  19. getFutureMessage(1.second).map { msg => Ok(msg) }
  20.  
  21. build.gradle
  22.  
  23. repositories {
  24. jcenter()
  25. maven {
  26. name "typesafe-maven-release"
  27. url "https://repo.typesafe.com/typesafe/maven-releases"
  28. }
  29. ivy {
  30. name "typesafe-ivy-release"
  31. url "https://repo.typesafe.com/typesafe/ivy-releases"
  32. layout "ivy"
  33. }
  34. }
  35.  
  36. apply plugin: "play"
  37. apply plugin: "scala"
  38. apply plugin: "idea"
  39.  
  40. model {
  41. components {
  42. play {
  43. platform play: '2.6.6', scala: '2.12'
  44. injectedRoutesGenerator = true
  45. }
  46. }
  47. }
  48.  
  49. idea {
  50. module {
  51. sourceDirs += file("app")
  52. testSourceDirs += file("test")
  53. scopes.COMPILE = [plus: [configurations.play], minus: []]
  54. scopes.RUNTIME = [plus: [configurations.playRun], minus: [configurations.play]]
  55. scopes.TEST = [plus: [configurations.playTest], minus: [configurations.playRun]]
  56. }
  57. }
  58.  
  59. package controllers
  60.  
  61. import akka.actor.ActorSystem
  62. import javax.inject._
  63. import play.api._
  64. import play.api.mvc._
  65. import scala.concurrent.{ExecutionContext, Future, Promise}
  66. import scala.concurrent.duration._
  67.  
  68. /**
  69. * This controller creates an `Action` that demonstrates how to write
  70. * simple asynchronous code in a controller. It uses a timer to
  71. * asynchronously delay sending a response for 1 second.
  72. *
  73. * @param actorSystem We need the `ActorSystem`'s `Scheduler` to
  74. * run code after a delay.
  75. * @param exec We need an `ExecutionContext` to execute our
  76. * asynchronous code.
  77. */
  78. @Singleton
  79. class AsyncController @Inject()(cc: ControllerComponents, actorSystem: ActorSystem)(implicit exec: ExecutionContext) extends AbstractController(cc) {
  80.  
  81. /**
  82. * Create an Action that returns a plain text message after a delay
  83. * of 1 second.
  84. *
  85. * The configuration in the `routes` file means that this method
  86. * will be called when the application receives a `GET` request with
  87. * a path of `/message`.
  88. */
  89. def message = Action.async {
  90. getFutureMessage(1.second).map { msg => Ok(msg) }
  91. }
  92.  
  93. private def getFutureMessage(delayTime: FiniteDuration): Future[String] = {
  94. val promise: Promise[String] = Promise[String]()
  95. actorSystem.scheduler.scheduleOnce(delayTime) { promise.success("Hi!") }
  96. promise.future
  97. }
  98.  
  99. }
Add Comment
Please, Sign In to add comment