如何在启动时防止喷涂路由器?

时间:2015-07-05 16:09:37

标签: scala spray

考虑以下代码:

import akka.actor.{ActorSystem, Props}
import akka.io.IO
import spray.can.Http

object Main extends App {

  implicit val system = ActorSystem()

  val handler = system.actorOf(Props[DemoServiceActor], name = "handler")

  IO(Http) ! Http.Bind(handler, interface = "localhost", port = 8080)
}

import akka.actor.Actor
import spray.routing.HttpService

class DemoServiceActor extends Actor with DemoService {

  def actorRefFactory = context

  def receive = runRoute(demoRoute)
}

trait DemoService extends HttpService {

  implicit def executionContext = actorRefFactory.dispatcher

  def demoRoute = {
    path("test") {
      get {
        println("ping")
        complete("test complete")
      }
    }
  }
}

main运行时,它会打印到控制台ping。为什么?如何解决这个问题?

0 个答案:

没有答案