【发布时间】: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 如果发布为答案,我很乐意将其标记为答案......