Spring by Example Web Module

David Winterfeldt


There is a Spring GWT Controller for standard GWT usage and also Spring Bayeux integration for using Comet on Jetty.

There is an ImageInterceptor that intercepts a request and looks in a directory that matches the requests relative path. Currently it only matches one image extension type which defaults to '.jpg'. It generates a thumbnail if one doesn't exist and also makes a list of available thumbnails and images. Also, GenericHtmlController is a generic annotation-based controller to handle html requests ('/**/*.html') is available. It's useful with Dynamic Tiles Spring MVC Module to allow rendering of static pages or dynamic ones that don't necessarily need to go through a controller to render.

1. Spring GWT Controller

Spring Configuration

Even though the service controller is annotation-based, since GWT calls RPC methods using reflection, the mapping has to be manually set using the SimpleUrlHandlerMapping.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"

    <context:component-scan base-package="org.springbyexample.web.gwt.server" />

    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
    <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />

    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="order" value="0" />
        <property name="mappings">

Code Example

public class ServiceController extends GwtController implements Service {

    final Logger logger = LoggerFactory.getLogger(ServiceController.class);

    private static final long serialVersionUID = -2103209407529882816L;

    private PersonDao personDao = null;
     * Finds person within a range.
    public Person[] findPersons(int startIndex, int maxResults) {
        Person[] results = null;

        List<Person> lResults = new ArrayList<Person>();

        Collection<org.springbyexample.orm.hibernate3.annotation.bean.Person> lPersons = personDao.findPersons(startIndex, maxResults);
        for (org.springbyexample.orm.hibernate3.annotation.bean.Person person : lPersons) {
            Person result = new Person();

        return lResults.toArray(new Person[]{});