6

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

}

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

4

2 回答 2

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/

于 2015-04-19T19:30:25.997 回答
0

正如@jrudolph 所说

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

于 2015-04-20T07:14:53.990 回答