我想一個簡單的噴霧的示例應用程序,我不能訪問的路線,我上傳的示例源代碼不工作,github上:我定義的爲什麼我會收到「請求的資源找不到」。訪問簡單的噴霧路線時?
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."
:spray-tomcat-example路線如下:
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>
}
}
}
}
}
和ofcourse我有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
@jrudolph我剛剛嘗試過'pathSingleSlash'我也遇到了同樣的錯誤,如果我用'path(「/ something」)替換路徑(「」)''那麼'/ sprayexapmle/something'也不適用於我。 .. – Jas
這個問題似乎是噴霧不是上下文路徑的剝離。因此,您需要設置'spray.servlet.root-path =「/ spraytomcat」'設置才能使其工作。請參閱https://github.com/spray/spray/blob/master/spray-servlet/src/main/resources/reference.conf#L37 – jrudolph