why do I get "The requested resource could not be found." when accessing simple spray route?

Jas*_*Jas 5 scala spray spray-dsl

I tried a simple spray example app and i cannot access the route, I uploaded the example source code which does not work to github: spray-tomcat-example:

 git clone https://github.com/avidanyum/spray-tomcat-example
 mvn package
 cp cp target/spray-tomcat-example-0.1-SNAPSHOT.war ~/tmp/tomcat/apache-tomcat-7.0.61/webapps/spraytomcat.war
 cd ~/tmp/tomcat/apache-tomcat-7.0.61/bin
 ./catalina.sh jpda run
 http://localhost:8080/spraytomcat/
Run Code Online (Sandbox Code Playgroud)

I get

"The requested resource could not be found."
Run Code Online (Sandbox Code Playgroud)

I defined the route as following:

class ServiceActor extends Actor with Service {

  def actorRefFactory = context
  def receive = runRoute(myRoute)
}

trait Service extends HttpService {
  import com.example.domain.Person

  val myRoute =
    path("") {
      get {
        respondWithMediaType(`text/html`) {
          complete {
            <html>
              <body>
                <h1>Say hello to <i>spray-routing</i> on <i>tomcat</i>!</h1>
              </body>
            </html>
          }
        }
      }
    }


}
Run Code Online (Sandbox Code Playgroud)

and ofcourse I have the boot class in place

in application.conf

spray.servlet {
  boot-class = "com.example.SprayBoot"
  request-timeout = 10s
}
Run Code Online (Sandbox Code Playgroud)

and SprayBoot itself:

class SprayBoot extends WebBoot {

  val system = ActorSystem("actorsystem")
  val serviceActor = system.actorOf(Props[ServiceActor])

}
Run Code Online (Sandbox Code Playgroud)

我很确定我遵循了所有要求,是否缺少任何东西?如何更新它以实际提供内容,而不是“找不到所请求的资源”。

Jas*_*Jas 0

正如@jrudolph 所说

问题似乎是喷雾没有剥离上下文路径。因此,您需要设置 Spray.servlet.root-path = "/spraytomcat" 设置才能使其工作。看这里