0

我正在尝试将backend我的GWT应用程序切换为Spring使用RestyGwt. 我遵循了这个例子:

  1. 站人
  2. 专区

现在我想知道该怎么办Entities。它们可以在客户端使用吗?我已经把它们放在Shared包里,但不幸的是我收到了一个错误:

gru 09, 2015 11:06:08 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Spring MVC Dispatcher Servlet] in context with path [/restgwt] threw exception [Handler processing failed; nested exception is java.lang.NoClassDefFoundError: com/google/gwt/core/client/GWTBridge] with root cause
java.lang.ClassNotFoundException: com.google.gwt.core.client.GWTBridge
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
    at com.sagar.restgwt.shared.OrderConfirmation.toString(OrderConfirmation.java:18)
    at java.lang.String.valueOf(String.java:2994)
    at java.lang.StringBuilder.append(StringBuilder.java:131)

这是我的课程:

客户端

@Path("/service")
public interface InfoService extends RestService {
    public static class Util {
        private static InfoService instance;

        public static InfoService getService() {
            if (instance == null) {
                instance = GWT.create(InfoService.class);
            }
            Resource resource = new Resource(GWT.getModuleBaseURL() + "service");
            ((RestServiceProxy) instance).setResource(resource);
            return instance;
        }
    }

    @GET
    @Path("/loadInfo")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public void getInfo(MethodCallback<OrderConfirmation> callback);
}
public void onModuleLoad() {

    Button button = new Button("Click Me");
    button.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            InfoService.Util.getService().getInfo(
                    new MethodCallback<OrderConfirmation>() {
                        @Override
                        public void onSuccess(org.fusesource.restygwt.client.Method method, OrderConfirmation response) {
                            RootPanel.get().add(
                                    new Label(
                                            "message: " + response.message + "  - ready time: " + response.ready_time)
                                    );
                        }
                        @Override
                        public void onFailure(org.fusesource.restygwt.client.Method method,
                                Throwable exception) {
                            // TODO Auto-generated method stub
                            GWT.log("Error");

                        }

                    });
        }
    });

服务器端

@Controller
public class RestGWTController {
    @RequestMapping(value = "/loadInfo", method = RequestMethod.GET, headers = "Accept=application/json")
    public @ResponseBody OrderConfirmation handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //GreetingServiceEndpoint endpoint = greetingService.getGreetingServiceEndpointPort();

        OrderConfirmation confirmation = new OrderConfirmation();
        //confirmation.message = endpoint.sayHello();
        confirmation.message = "Hello";
        confirmation.ready_time = System.currentTimeMillis() + 1000 * 60 * 30;
        System.out.println("hit server");
        return confirmation;
    }
}

共享模块

public class OrderConfirmation {
    public String message;
    public Long ready_time;
    /**
     * Example of how to create an instance of a JsonEncoderDecoder for a data
     * transfer object.
     */
    public interface OrderConfirmationJED extends JsonEncoderDecoder<OrderConfirmation> {
    }
    @Override
    public String toString() {
        if (GWT.isClient()) {
            OrderConfirmationJED jed = GWT.create(OrderConfirmationJED.class);
            return jed.encode(this).toString();
        }
        return super.toString();
    }
}

现在我考虑DTOshared模块和Entity服务器上。我这个是对的。我的问题是:

  1. 为此目的,什么是好的设计模式。
  2. 服务器端实体可以序列化为json,并在客户端用作gwt中的Java对象吗?

请给我一些帮助。

4

1 回答 1

0

您缺少 gwt-servlet.jar 依赖项。

Maven 配置

它需要<scope>compile</scope>是默认的。其他 gwt-jars 可以是<scope>provided</scope>

            <dependency>
                    <groupId>com.google.gwt</groupId>
                    <artifactId>gwt-servlet</artifactId>
                    <version>${gwt.version}</version>
            </dependency>
于 2015-12-10T23:07:58.020 回答