首页 文章

无法在lagom中使用'call'方法

提问于
浏览
0

我正在尝试使用Lagom来检查如何调用 callpathCallnamedCall . 我正在关注lagom的教程 . 我创建了一个新服务并使用以下网址打开了网址,但是我收到错误

使用的URL(我希望看到hello2响应)

http://localhost:9000/

错误

GET\Q/stream\EService: hello-stream (http://0.0.0.0:58322)
2GET\Q/api/hello/\E([^/]+)Service: hello (http://0.0.0.0:57797)
3POST\Q/api/hello/\E([^/]+)Service: hello (http://0.0.0.0:57797)
**4POST\Q/hello2\EService: hello (http://0.0.0.0:57797)**

我已经完成了以下步骤

下载模板后(参见https://www.lagomframework.com/documentation/1.3.x/scala/IntroGetStarted.html),我更改了代码以添加新的服务调用(称为hello2) . 以下是我在HelloService.scala中添加的代码

named("hello")
      .withCalls(
        pathCall("/api/hello/:id", hello _),
        pathCall("/api/hello/:id", useGreeting _),
        call(hello2) //added this line in default template.
      )

我已将hello2定义为(在HelloService.scala中)

def hello2: ServiceCall[String, String]

HelloServiceImpl.scala中的代码是

override def hello2 = ServiceCall {
    Future.successful("Hello2")
  }

Questin 1 - 错误是什么(我猜我没有正确地从浏览器调用服务)?

1 回答

  • 2

    当你说“我想我没有正确地从浏览器调用服务”时,你的意思是你只是浏览浏览器中的URL吗?如果是这样,这将无法工作,因为hello2被定义为POST endpoints ,您的浏览器将发送GET请求 .

    hello2被定义为POST endpoints ,因为在ServiceCall定义中它接收请求消息 . (有关详细信息,请参阅https://www.lagomframework.com/documentation/1.3.x/java/ServiceDescriptors.html . )

    如果您将请求消息类型从 String 更改为 NotUsed ,则Lagom应该开始生成GET endpoints .

相关问题