Scala - Spray.io - sbt-revolver - jrebel - 在重新加载时看不到对HttpService(或任何东西)的更改

时间:2013-02-24 08:17:26

标签: scala jrebel spray

我可以看到sbt-revolver已设置并在spray can上运行,但是当我向服务发出请求时,我的更改不会出现。

你可以在日志中看到jrebel正在做的事情:

    [success] Total time: 1 s, completed Feb 24, 2013 3:13:18 AM
app: [INFO] [02/24/2013 03:13:19.497] [com-example-Boot-spray.io.io-bridge-dispatcher-7] [akka://com-example-Boot/user/io-bridge] akka://com-example-Boot/user/io-bridge started
app: [INFO] [02/24/2013 03:13:19.851] [com-example-Boot-akka.actor.default-dispatcher-2] [akka://com-example-Boot/user/http-server] akka://com-example-Boot/user/http-server started on localhost/127.0.0.1:9000
>                 ~products
[success] Total time: 0 s, completed Feb 24, 2013 3:13:23 AM
1. Waiting for source changes... (press enter to interrupt)
[info] Compiling 1 Scala source to /Users/tripled153/Development/src/Foundationv2/spray-template/target/scala-2.10/classes...
[success] Total time: 2 s, completed Feb 24, 2013 3:13:33 AM
2. Waiting for source changes... (press enter to interrupt)

但更新我的特征中的消息并不会在刷新时出现。

package com.example

import akka.actor.Actor
import spray.routing._
import spray.http._
import MediaTypes._


// we don't implement our route structure directly in the service actor because
// we want to be able to test it independently, without having to spin up an actor
class MyServiceActor extends Actor with MyService {

  // the HttpService trait defines only one abstract member, which
  // connects the services environment to the enclosing actor or test
  def actorRefFactory = context

  // this actor only runs our route, but you could add
  // other things here, like request stream processing
  // or timeout handling
  def receive = runRoute(myRoute)
}


// this trait defines our service behavior independently from the service actor
trait MyService extends HttpService {

  val myRoute =
    path("") {
      get {
        respondWithMediaType(`text/html`) { // XML is marshalled to `text/xml` by default, so we simply override here
          complete {
            <html>
              <body>
                <h1>Say hello to <i>spray-routing</i> on <i>spray-can</i>!</h1>
              </body>
            </html>
          }
        }
      }
    }

}

这是建立在喷雾罐的例子上,它上面设有左轮手枪。 https://github.com/spray/spray-template

3 个答案:

答案 0 :(得分:2)

问题是路由仅在服务启动时构建一次。尝试使用dynamic指令包装完整路径,以便为每个请求重建它。

编辑:请参阅此主题的mailing list thread

答案 1 :(得分:1)

请确保您已将JREBEL_PATH设置为jrebel.jar 绝对路径的副本。

答案 2 :(得分:0)

我正在使用重新启动命令而JRebel没有捕获任何更改。然后我这样做了:

在一个终端会话中启动sbt并运行start命令(这是启动,而不是重启命令)

打开另一个终端会话并使用命令~complech运行sbt。

就是这样,在两个单独的窗口中运行SBT并使用start和~corite命令就可以了。

显然,JRebel必须处于活动状态且具有有效许可证。

请记住,当源代码发生变化时,JRebel不会重新加载绝对所有内容。请特别注意缓存的值,如缓存的路由或数据。在这种情况下,您需要编写一个简单的技巧来强制缓存重新加载,可能是基于时间的,或者只是查询文件锁,甚至是JRebel生效的可重新加载的类中的简单属性。

相关问题