Skip navigation


  • JSON is popular data exchange format and well suited for JavaScript consumption


Spring and GWT Integration using JSON

  • Most GWT application needs to interact with a backend server. GWT provides RequestBuilder class and JavaScriptObject class to allow to you to make calls to Java servlets.
  • Spring MVC allows you to receive the GWT request, process the request and returns data in JSON format.





Spring GWT StockWatcher


GWT team has already provided documents describing how to create client requests and how to process JSON reply. I am going to show you how to use Spring Framework to process the GWT request and return JSON data.


Step 1: 

       Create a Spring MVC application


Step 2:   

     Add Jackson Java JSON processor dependency in your pom file.








Step 3:

Create a controller to process the GWT requests





public class JSONController {

       private static final double MAX_PRICE = 100.0; // $100.00

       private static final double MAX_PRICE_CHANGE = 0.02; // +/- 2%



       @RequestMapping(method = RequestMethod.GET)

       public @ResponseBody List<StockPrice> getStocks( @RequestParam(value = "q", required = false) final String q ) {


              String[] stockSymbols = q.split(" ");

              ArrayList<StockPrice> stockPriceList= new ArrayList<StockPrice>();

                  for (String stockSymbol : stockSymbols) {

                   Random rnd = new Random();

                    double price = rnd.nextDouble() * MAX_PRICE;

               double change = price * MAX_PRICE_CHANGE * (rnd.nextDouble() * 2f - 1f);

                    StockPrice stockPrice = new StockPrice();








              return stockPriceList;






Step 4:

     Configure Spring mvc annotation


<beans xmlns=""


       xmlns:mvc="" xmlns:xsi=""

       xsi:schemaLocation="    ">


       <context:component-scan base-package="com.johnnyweb.stockWatcher.controller" />


       <mvc:annotation-driven />




Step 5:

     Configure web.xml file


<web-app id="WebApp_ID" version="2.4"

       xmlns="" xmlns:xsi=""



       <display-name>Spring Web MVC Application</display-name>
























Step 6:

     Test your application

Filter Blog

By date:
By tag: