Spray akka deploy to web server
I have an application built with spray + akka. using this guide:
http://sysgears.com/articles/building-rest-service-with-scala/
This explains the following example: https://github.com/oermolaev/simple-scala-rest-example
The app works fine. But when trying to deploy to a web server, I couldn't find a way to do this.
I tried to use xsbt-web-plugin to deploy to Tomcat, got the following input:
~container:start
[info] starting server ... Adding context for target / webapp ...
Starting Tomcat Service Starting Servlet:
Apache Tomcat / 7.0.34 org.apache.catalina.startup.ContextConfig
getDefaultWebXmlFragment INFO: Global web.xml not found
org.apache.coyote.AbstractProtocol start INFO: Start
ProtocolHandler ["http-nio-8080"]
But Tomcat returns 404 for all requests.
Does anyone know how I can deploy akka spray application to Tomcat?
source to share
Solved a problem.
This is what you need for the xsbt-plugin to work with your spray application:
- Set
root-path
in application.conf
As @jrudolph explained: serpentine doesn't know to figure it out automatically on tomcat:
spray.servlet {
boot-class = "com.sysgears.example.boot.Boot"
root-path = "/rest"
request-timeout = 10s
}
-
Modify the class
boot
to extendwebBoot
:
boot.scala
class Boot extends WebBoot {
// create an actor system for application
val system = ActorSystem("rest-service-example")
// create and start rest service actor
val serviceActor = system.actorOf(Props[RestServiceActor], "rest-endpoint")
}
-
add web.xml as described in xsbt-web-plugin:
Src / main / webapp / WEB-INF / web.xml:
<listener> <listener-class>spray.servlet.Initializer</listener-class> </listener> <servlet> <servlet-name>SprayConnectorServlet</servlet-name> <servlet-class>spray.servlet.Servlet30ConnectorServlet</servlet-class> <async-supported>true</async-supported> </servlet> <servlet-mapping> <servlet-name>SprayConnectorServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
For a complete change, see the comparison on github (sample script generously generates this thread for tomcat users)
https://github.com/oermolaev/simple-scala-rest-example/compare/spray-tomcat
source to share