Skip to content

Integration with Spring

Gael Lazzari edited this page Aug 27, 2012 · 3 revisions

Since a GWT application usually deals with a backend server, you may be interested in using Spring to manage your server components, like RPC services. Some simple frameworks, like gwtrpc-spring could handle the glue code beetwen Spring and GWT remote services for you.

But you also might want to test your entire stack. That's why gwt-test-utils comes with some classes to do it very easily.

How to use

@ContextConfiguration(locations = {"classpath:applicationContext-test.xml"}, loader = GwtTestContextLoader.class)
@GwtModule("com.googlecode.gwt.test.sample.SpringSample")
public class DemoSpringTest extends GwtSpringTest {

  @Autowired
  private MyService myService;

   // your test methods go here...
}
  1. First, extend GwtSpringTest, the base class for test with Spring.
  2. Use the ContextConfiguration annotation from spring-test to configure your test context. gwt-test-utils provides a GwtTestContextLoader you must declare as the custom context loader.
  3. Like with GwtTest, you have to set the module under test with the @GwtModule annotation.
  4. That's it !

Your GwtSpringTest subclasses can be injected with @Autowired beans, and hold a reference to the test ApplicationContext through the GwtSpringTest.getApplicationContext() protected method.
Also note that your RPC servlets will automatically be binded to their corresponding RemoteService interfaces !

If you want to write a CSV test scenario which should be integrated with Spring, just extend GwtSpringCsvTest instead of GwtSpringTest :-)

You can fork sample-spring and sample-spring-csv projects to see complete GWT + Spring applications and how to test them using gwt-test-utils.

Overriding default behaviour

TODO