Why am I getting "The requested resource was not found". when accessing a simple spray route?

I tried a simple spray application and I can't access the route, I downloaded the source code of the example that doesn't work for 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/

      

I get

"The requested resource could not be found."

      

I have defined the route as follows:

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>
          }
        }
      }
    }


}

      

and of course i have a class boot

in place

in application.conf

spray.servlet {
  boot-class = "com.example.SprayBoot"
  request-timeout = 10s
}

      

and SprayBoot

:

class SprayBoot extends WebBoot {

  val system = ActorSystem("actorsystem")
  val serviceActor = system.actorOf(Props[ServiceActor])

}

      

I am sure I followed all the requirements, am I missing something? how can I update it to actually serve the content instead of "The requested resource was not found."

+3


source to share


2 answers


as @jrudolph said



The problem is that the spray is not stripping the context of the track. So, you need to set spray.servlet.root-path = "/ spraytomcat" to make it work. See here

0


source


The example will work when deploying the application in a ROOT context without additional configuration.

I changed your script a bit:



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


source







All Articles