ReviewIn the previous section, we have discussed how to generate a simple GWT application using the GWT Maven plugin. In this section, we will study how to integrate Spring and GWT using the GWTHandler library via configuration and modifying existing classes.
Table of ContentsPart 1: Introduction and Functional Specs
Part 2: Generating the GWT project
Part 3: Integrating Spring and GWTHandler
Part 4: Running the Application
What is GWTHandler?
The GWTHandler is part of the GWT Server Library--a collection of Java server side components for the Google Web Toolkit AJAX framework with the current focus on the Spring framework by facilitating publishing of Spring beans as RPC services.
The GWTHandler allows you to quickly map multiple RPC service beans to different URLs very similar to the way Spring's SimpleUrlHandlerMapping maps URLs to controllers.
ConfigurationThe initial step in configuring the GWTHandler is to declare our XML configuration files:
In the web.xml the part that you need to pay extra attention is the url-pattern. Here we've declared the pattern as /gwtmodule/rpc/*. This means all RPC calls should follow that pattern!
The gwt-servlet.xml is nothing but a simple bean declaration. Here we've declared a GWTHandler bean, and it contains one mapping. We've mapped all calls to /greet to be processed by a GreetingService implementation. Remember this is an RPC call,sSo if you have plans of calling this RPC mapping, you must also take account the mapping the gwt-servlet.xml! In other words, the complete path is rpc/greet.
In the applicationContext.xml we've basically enabled annotation scanning.
ClassesThe second step in configuring the GWTHandler is to modify our existing classes to take advantage of the GWTHandler.
We will create a new service class:
And edit the following classes:
The SpringService basically prints out a Hello *name* from Spring 3.1 message.
As discussed earlier, to use the /greet RPC mapping, we have to consider the parent mapping from the gwt-servlet.xml as well. In other words, the complete mapping for this RPC is rpc/greet
Next we modify the GreetingServiceImpl to take advantage of the SpringService implementation. So instead of the original reply that includes server information, we're now returning a simple "hello" message instead.
For completion purposes, we will also show the contents of the gwtmodule class, though nothing has been changed.
NextIn the next section, we will build and run the application using Maven, and show how to import the project in Eclipse. Click here to proceed.
Share the joy:
Subscribe by reader Subscribe by email Share