【问题标题】:spray akka deployment on webserver在网络服务器上喷洒 akka 部署
【发布时间】:2015-04-27 13:09:02
【问题描述】:

我有一个基于 spray + akka 的应用程序。使用本指南:

http://sysgears.com/articles/building-rest-service-with-scala/

它解释了这个例子:https://github.com/oermolaev/simple-scala-rest-example

应用程序运行良好。但是当尝试在 webServer 上进行部署时,我没有找到办法。

我尝试使用 xsbt-web-plugin 在 Tomcat 上部署,得到以下输入:

 ~container:start

[info] 启动服务器...为目标/webapp 添加上下文...

启动服务Tomcat启动Servlet引擎:

Apache Tomcat/7.0.34 org.apache.catalina.startup.ContextConfig

getDefaultWebXmlFragment INFO:找不到全局 web.xml

org.apache.coyote.AbstractProtocol 开始信息:开始

ProtocolHandler ["http-nio-8080"]

但是 Tomcat 对所有请求都返回 404。

有人知道如何在 Tomcat 上部署 spray akka 应用程序吗?

【问题讨论】:

  • 看到这个问题,spray-servlet在tomcat上自动找出上下文路径好像有问题,所以需要手动设置:stackoverflow.com/questions/29701593/…
  • 您是否尝试在您的application.conf 中更改spray.servlet.root-path
  • 是的,它有帮助,谢谢。我现在的问题是在 web.xml 中定义为 的内容
  • @griffonvul​​ture - 我能问一下为什么要在 Web 服务器(容器)上部署 Spray 吗? Spray 本身是无容器的,可以部署为可运行的 jar 文件。你考虑过那个选项吗?您还可以将您的流量从 Web 服务器重定向到 Spray 实例。

标签: java scala akka spray xsbt-web-plugin


【解决方案1】:

解决了这个问题。

这是使 xsbt-plugin 与喷雾应用程序一起工作所需要的:

  1. 在application.conf中设置root-path

正如@jrudolph 指出的那样:spray servlet 不知道在 tomcat 上自动解决:

spray.servlet {
   boot-class = "com.sysgears.example.boot.Boot"
   root-path = "/rest"
   request-timeout = 10s
 } 
  1. 更改类 boot 以扩展 webBoot

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")
}
  1. 按照 xsbt-web-plugin 中的说明添加 web.xml:

    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>
    

完整的变化见github上的比较(示例作者慷慨地为tomcat用户生成了这个分支)

https://github.com/oermolaev/simple-scala-rest-example/compare/spray-tomcat

【讨论】:

猜你喜欢
  • 2016-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-09
  • 2012-02-24
  • 1970-01-01
  • 2016-10-26
相关资源
最近更新 更多