如何使用scala喷雾分离器? [英] how to use scala spray detach?

查看:74
本文介绍了如何使用scala喷雾分离器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用喷雾分离器,如下所示:

i'm trying to use spray detach as following:

path("") {
  get {
    detach {
      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>Jetty</i>!</h1>
            </body>
          </html>
        }

      }
    }
  }
}

,但出现以下编译错误:

but i get following compilation error:


类型不匹配;找到:spray.routing.RequestContext =>需要的单位
:spray.routing.directives.DetachMagnet
responseWithMediaType( text / html ){// XML默认情况下被编组为 text / xml ,因此我们只需在此处覆盖
^

type mismatch; found : spray.routing.RequestContext => Unit required: spray.routing.directives.DetachMagnet respondWithMediaType(text/html) { // XML is marshalled to text/xml by default, so we simply override here ^

我查看了: https://github.com/spray/spray/wiki/分离,我仍然不知道我在做什么错...

I looked at: https://github.com/spray/spray/wiki/Detach and I still have no idea what i'm doing wrong...

推荐答案

不推荐使用的文档。如果要阅读当前文档,则必须查看 spray.io 网站。

You are looking at a deprecated documentation. If you to want to read the current documentation you have to look at the spray.io website.

关于您的问题,当前文档为 detach 指令指定了不同的签名-请参阅此处

Regarding your problem, the current documentation specifies a different signature for the detach directive - see here

def detach()(implicit ec: ExecutionContext): Directive0
def detach()(implicit refFactory: ActorRefFactory): Directive0
def detach(ec: ExecutionContext): Directive0

当我隐式传递ExecutionContext时,您必须写上括号:

As you are passing your ExecutionContext implicitly I guess, you have to write the parenthesis:

detach() {
  respondWithMediaType(`text/html`) { // XML is marshalled to `text/xml` by default, so we simply override here
    complete { ...

这篇关于如何使用scala喷雾分离器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆