【问题标题】:why do I get "The requested resource could not be found." when accessing simple spray route?为什么我会收到“找不到请求的资源”。访问简单的喷雾路线时?
【发布时间】:2015-04-20 15:14:53
【问题描述】:

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

}

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

【问题讨论】:

  • 试试pathSingleSlash 而不是path("")
  • @jrudolph 我刚刚尝试过pathSingleSlash,如果我将path("") 替换为path("/something") 然后/sprayexapmle/something 也对我不起作用...
  • 问题似乎是喷雾没有剥离上下文路径。因此,您需要设置spray.servlet.root-path = "/spraytomcat" 设置才能使其工作。请参阅github.com/spray/spray/blob/master/spray-servlet/src/main/…
  • @jrudolph 如果发布为答案,我很乐意将其标记为答案......

标签: scala spray spray-dsl


【解决方案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/

【讨论】:

    【解决方案2】:

    正如@jrudolph所说的

    问题似乎是喷雾没有剥离上下文 小路。所以,你需要设置 spray.servlet.root-path = "/spraytomcat" 设置使其工作。见here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多