为什么我得到"找不到所请求的资源。"当访问简单的喷涂路线?

时间:2015-04-17 14:09:22

标签: scala spray spray-dsl

我尝试了一个简单的喷涂示例应用程序而我无法访问该路径,我上传了对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课程

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])

}

我很确定我错过了所有要求吗?如何更新它以实际提供内容而不是“无法找到所请求的资源。”

2 个答案:

答案 0 :(得分:1)

当您将应用程序部署到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/

答案 1 :(得分:0)

正如@jrudolph所说

  

问题似乎是喷雾不是剥离的背景   路径。所以,你需要设置spray.servlet.root-path =“/ spraytomcat”   设置使它工作。见here