【问题标题】:Call Spring MicroService from gwt从 gwt 调用 Spring MicroService
【发布时间】:2018-11-05 19:37:04
【问题描述】:

我有一个需要调用 Spring Boot 微服务的 GWT 客户端。我认为它可以类似于调用一个 REST Web 服务,但是有没有更好的方法来做到这一点?

【问题讨论】:

  • 如果你的spring boot微服务是基于REST的服务,如果YES你可以调用类似于调用rest web服务,我们使用RequestBuilder来调用我们的spring boot REST微服务
  • 你能达到“更好”的条件吗? Spring Boot 微服务的重点是几乎任何东西都可以调用它,它并不特定于任何一种技术,对吧?
  • @ColinAlworth 我的意思是如果有任何库可以处理所有样板代码并提供一些模板可以轻松调用 Spring Boot 微服务
  • 如果服务是基于 HTTP 的 JSON REST 服务,我推荐resty-gwt.github.io

标签: spring gwt microservices


【解决方案1】:

您或许可以使用RequestBuilder 从您的 GWT 应用程序的客户端调用您的 API:

import com.google.gwt.http.client.RequestBuilder;

// ....

try {
    new RequestBuilder(
            RequestBuilder.GET, // GET, POST, etc.
            url                 // url of your microservice endpoint
    ).sendRequest(null, new RequestCallback() { // replace null with your req body if needed
        @Override
        public void onResponseReceived(Request req, Response resp) {
            // Parse resp.getText() which is hopefully a JSON string
        }
        @Override
        public void onError(Request res, Throwable throwable) {
            // handle errors
        }
    });
} catch (RequestException e) {
    // log, rethrow... the usual
}

【讨论】:

猜你喜欢
  • 2020-02-10
  • 1970-01-01
  • 2021-02-15
  • 1970-01-01
  • 2017-08-22
  • 1970-01-01
  • 1970-01-01
  • 2011-06-23
  • 1970-01-01
相关资源
最近更新 更多