为什么我在访问简单的喷涂路线时得到 "The requested resource could not be found."?

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

我尝试了一个简单的喷雾示例应用程序,但我无法访问路线,我上传了不起作用的示例源代码到 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/

我明白了

"The requested resource could not be found."

我定义的路线如下:

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>
          }
        }
      }
    }


}

当然我有 boot class

application.conf

spray.servlet {
  boot-class = "com.example.SprayBoot"
  request-timeout = 10s
}

SprayBoot本身:

class SprayBoot extends WebBoot {

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

}

我很确定我遵循了所有要求,我是否遗漏了什么?我怎样才能更新它以实际提供内容而不是 "The requested resource could not be found."

当您将应用程序部署到 ROOT 上下文而无需任何额外配置时,该示例将起作用。

我稍微修改了你的脚本:

git clone https://github.com/avidanyum/spray-tomcat-example mvn package cp target/spray-tomcat-example-0.1-SNAPSHOT.war ~/tmp/tomcat/apache-tomcat-7.0.61/webapps/ROOT.war cd ~/tmp/tomcat/apache-tomcat-7.0.61/bin ./catalina.sh jpda run wget http://localhost:8080/

正如@jrudolph所说

The problem seems to be that spray isn't stripping of the context path. So ,you need to set spray.servlet.root-path = "/spraytomcat" setting to make it work. See here