【问题标题】:Fetching data from a microservice to rest in grails从微服务中获取数据以存放在 grails 中
【发布时间】:2019-03-28 06:14:41
【问题描述】:

我有一个休息和一个微服务。在微服务中我有一个表,我希望该表数据被提取到休息,我在休息演示控制器中编写了以下方式。

def result = restBuilder().post("http://localhost:2222/api/microservice/fetchData"){
            header 'authorization', 'fdgtertddfgfdgfffffff'
            accept("application/json")
            contentType("application/json")
            json "{'empId':1,'ename':'test1'}"
        }

但它会引发错误“没有方法签名:demoController.restBuilder() 适用于参数类型:() 值:[]”。我应该如何从微服务中获取数据以进行休息?

【问题讨论】:

标签: grails microservices


【解决方案1】:

您正在调用一个名为restBuilder() 的方法,但该方法不存在。如果你想让它工作,你需要实现那个方法并让它返回一些可以处理对post(String, Closure)的调用的东西。

您可能打算使用RestBuilder 类。具体细节取决于您使用的 Grails 版本,但您可能想要的是这样的......

RestBuilder restBuilder = new RestBuilder()
restBuilder.post('http://localhost:2222/api/microservice/fetchData'){
    header 'authorization', 'fdgtertddfgfdgfffffff'
    accept 'application/json'
    json {
        empId = 1
        name = 'test1'
    }
}

您可能需要在 build.gradle 中添加对 grails-datastore-rest-client 的依赖项。

compile "org.grails:grails-datastore-rest-client"

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-15
    • 1970-01-01
    • 2021-08-06
    • 1970-01-01
    • 1970-01-01
    • 2020-11-24
    • 2018-04-28
    • 1970-01-01
    相关资源
    最近更新 更多