GWT + Spring MVC (RESTful web services)

2019-04-02 02:35发布

问题:

I've been thinking all the day about how I can setup Spring MVC 3.0 (more specifically REST capabilities), with GWT. That is, I don't wanna use GWT RPC anymore, the communication will be made through REST. The problem is that I'm very new with the Spring Framework, and the only tutorials I found, they were using JSP, that's exactly where I get stuck... Is there a way to play with Spring without JSP page, only using the GWT view?

回答1:

I assume what your trying to do is have a Spring controller return JSON or XML data?

There are two ways to do this:

  1. use a ContentNegotiatingViewResolver
  2. use HttpMessageConverters in combination with the @ResponseBody annotation

Both methods are covered in some detail here : http://hillert.blogspot.com/2011/01/rest-with-spring-contentnegotiatingview.html

The spring people cover the @RequestBody method here: http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/

Here is the blog post covering the ContentNegotiatingViewResolver : http://blog.springsource.com/2009/03/08/rest-in-spring-3-mvc/

Sample code can be found at : https://src.springframework.org/svn/spring-samples/mvc-ajax/trunk/

I hope this helps.