2015-12-09 23 views
0

我正在尝试使用RestyGwt将我的GWT应用程序的backend切换为Spring。 我也跟着这样的例子:RestyGWT和Spring。如何管理客户端上的实体和模型。错误:java.lang.NoClassDefFoundError:com/google/gwt/core/client/GWTBridge

  1. ekito
  2. dzone

现在我不知道如何处理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(); 
    } 
} 

现在我想起shared模块上的DTO和服务器上的Entity。我这是正确的。 我的问题是:

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

请给我一些帮助。

回答

0

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

Maven配置

它需要<scope>compile</scope>这是缺省值。其他gwt-jar可以是<scope>provided</scope>

  <dependency> 
        <groupId>com.google.gwt</groupId> 
        <artifactId>gwt-servlet</artifactId> 
        <version>${gwt.version}</version> 
      </dependency> 
相关问题