Beginning from GWT 2.4 the integration of the RequestFactory API with Spring services on the backend is easy all you need to do is create a custom ServiceLocator on your server which will be used by GWT to locate properly the called services :
public class SpringServiceLocator implements ServiceLocator {
public Object getInstance(Class clazz) {
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(
RequestFactoryServlet.getThreadLocalServletContext());
return context.getBean(clazz);
}
}
The second step is to declare you RequestFactory servlet on your web.xml like this, (I assume that you have already spring set up) :
<servlet> <servlet-name>requestFactoryServlet</servlet-name> <servlet-class>org.gxpenses.util.SpringRequestServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>requestFactoryServlet</servlet-name> <url-pattern>/gwtRequest</url-pattern> </servlet-mapping>
As usual on the GWT part you have to configure your Proxies (because you use service style backend, you have to use ValueProxy instead of the EntityProxy) and your Requests which are the remote interfaces of your services :
//Note that I inherit from the ValueProxy object
@ProxyFor(Account.class)
public interface AccountProxy extends ValueProxy {
public String getId();
public void setId(String id);
public String getName();
public void setName(String name);
public Double getBalance();
public void setBalance(Double balance);
public String getType();
public void setType(String type);
}
//You have to provide you service Impl class, and the ServiceLocator you created
//Note that Account is automatically to AccountProxy on the client
@Service(value=AccountsServiceImpl.class, locator=SpringServiceLocator.class)
public interface AccountRequest extends RequestContext {
abstract Request<Void> createNewAccount(AccountProxy account);
abstract Request<Void> updateAccountBalance(String accountId, Double transactionAmount, String type);
abstract Request<Double> totalAmountByAccountAndPeriodeAndType(String accountId, Date start, Date end, String type);
}
Thatβs it for the integration, for more informations on how to use the RequestFactory API see : RequestFactory API
Reference: Spring GWT Integration using the RequestFactory API from our JCG partner Idriss Mrabti at the Fancy UI blog.
Related Articles :
- GWT 2 Spring 3 JPA 2 Hibernate 3.5 Tutorial β Eclipse and Maven 2 showcase
- GWT 2 Spring 3 JPA 2 Hibernate 3.5 Tutorial
- Building your own GWT Spring Maven Archetype
- Bootstrapping a web application with Spring 3.1 and Java based Configuration, part 1
- GWT Spring and Hibernate enter the world of Data Grids
- Testing GWT Apps with Selenium or WebDriver
- GWT, GWT-Ext (SmartGWT), GXT (Ext GWT) Common Tasks
- GWT EJB3 Maven JBoss 5.1 integration tutorial
- Getting Started with SmartGWT for awesome GWT interfaces
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Thank you!
We will contact you soon.
Tags
Google GWT Spring
π Photo of Idriss Mrabti
Idriss MrabtiDecember 16th, 2011Last Updated: August 21st, 2013
Idriss MrabtiDecember 16th, 2011Last Updated: August 21st, 2013
0 155 1 minute read

This site uses Akismet to reduce spam. Learn how your comment data is processed.