The class below can be used as a base to GWT RPC server-side classes to inject spring dependencies
package com.al.gwtutil; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import org.springframework.beans.factory.access.BeanFactoryLocator; import org.springframework.beans.factory.access.BeanFactoryReference; import org.springframework.beans.factory.access.SingletonBeanFactoryLocator; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.context.ApplicationContext; /** * @author alouet */ public abstract class SpringDependencyInjectionRemoveServiceServlet extends RemoteServiceServlet { public SpringDependencyInjectionRemoveServiceServlet() { super(); // requires beanRefFactory.xml file to be in the classpath BeanFactoryLocator bfl = SingletonBeanFactoryLocator.getInstance(); // requires one bean with id gwt-template-app to be defined in beanRefFactory.xml ( typically a ClassPathXmlApplicationContext) BeanFactoryReference bfr = bfl.useBeanFactory("gwt-context"); ApplicationContext ac = (ApplicationContext)bfr.getFactory(); AutowireCapableBeanFactory beanFactory = ac.getAutowireCapableBeanFactory(); // process annotation callbacks beanFactory.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_NO, true); // apply annotation- driven dependency injection beanFactory.initializeBean(this, "DummyNameFrom_SpringDependencyInjectionRemoveServiceServlet"); // apply callbacks } } for example: package com.al.templategwtapp.server; import javax.servlet.ServletException; import com.al.gwtutil.SpringDependencyInjectionRemoveServiceServlet; import com.al.templategwtapp.biz.MyBizClass; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Configurable; /** * @author Arnaud Louet */ public class SampleServiceImpl extends SpringDependencyInjectionRemoveServiceServlet implements com.al.templategwtapp.client.SampleService { @Autowired // indication to inject actual bean from spring container private MyBizClass myBean; public SampleServiceImpl() { super(); } public String getCurrentTime() { return myBean.getCurrentTimeAsString(); } } 2 Config files are required: beanRefFactory.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http:// www.springframework.org/dtd/spring-beans-2.0.dtd"> <beans> <bean id="gwt-context" lazy-init="true" class="org.springframework.context.support.ClassPathXmlApplicationContext"> <constructor-arg> <value>com/al/templategwtapp/server/gwt-template-app- applicationContext.xml</value> </constructor-arg> </bean> </beans> and a file to describe the application context: gwt-template-app- applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/ beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <context:annotation-config/> <bean id="myBizBean" class="com.al.templategwtapp.biz.MyBizClass" / > </beans> Arnaud. On Feb 13, 3:11 pm, Arthur Kalmenson <arthur.k...@gmail.com> wrote: > That book gives some good information on how to integrateSpringwith > GWT. Unfortunately, it's become rather dated and focuses on building > Web sites with GWT aspects rather then building Web applications.SpringMVC > can still be used with GWT to make the server side for your > GWT-RPC interfaces. > > -- > Arthur Kalmenson > > On Thu, Feb 12, 2009 at 2:48 PM, Jorge Guerrero Damian > > <jorge.guerrer...@gmail.com> wrote: > > I have some of experience working withSpringMVC and Velocity in the view. > > WithSpringMVC you can send to the view POJOs, and from the client I > > receive the data with GET/POST. > > > you can take a look to this linkhttp://noon.gilead.free.fr/gilead/ > > maybe can be usefull. > > > I'm starting to read a book when integrate GWT with hibernate,springmvc > > andspringsecurity, and more > >http://code.google.com/p/tocollege-net/, > > take a look, can be interesting for you > > > 2009/2/12 Christoph <g...@innovationowl.com> > > >> Thanks Jorge, for you info. > > >> After a bit more research, I posted a similar question on theSpring > >> forum, with a bit more detail: > >>http://forum.springsource.org/showthread.php?t=67423 > > >> It a first glance, it appears that Springs MVC is tailored to > >> traditional form based HTTP GET/POST type web clients. Our domain > >> model is done with POJOs that we transmit back and forth between > >> client/server using GWT's Java serialization abilities. On the client > >> side we have a decent separation between model and view. From what I > >> can tell, since our application sends parts of the model to the > >> client, I'm not sure that some of the traditional web MVC stuff is > >> useful for us, since our app is more of rich-client/server RPC. GWT > >> changes the architecture, for the better, away from the traditional > >> model only on the server approach. > > >> The IoC, DAO, and ORM stuff looks really useful. > > >> On Feb 12, 9:52 am, Jorge Guerrero Damian <jorge.guerrer...@gmail.com> > >> wrote: > >> > I'm starting to learn gwt, but I know something aboutspring. > >> > -Springis powerfull with security issues (I recomend that) > >> > - TheSpringMVC module is usefull to have a clean separation of the > >> > code. > >> > -Springhave a great integration with hibernate, in topics like > >> > sessions, > >> > transactions, and others. > > >> > I don't have experience with the integration of the 3, but I starting to > >> > learn about that. > > >> > 2009/2/11 Christoph <g...@innovationowl.com> > > >> > > We have a Tomcat-based GWT application that we are looking to scale. > >> > > Our persistence up until this point has been all via XML. We are have > >> > > chosen to integrate with Hibernate and see a lot of talk about the > >> > >SpringFramework. So my questions to the GWT community are this: > > >> > > What benefit doesSpringgive us over integrating Hibernate without > >> > >Spring? > > >> > > If it makes sense to integrate withSpring, what features ofSpring > >> > > should we use? > > >> > > Thanks, > >> > > Christoph > > >> > -- > >> > Jorge Guerrero Damián > >> > Ingeniero Civil en Informática > >> > Egresado de Magister en Ciencias de la Ingeniería Informática > >> > U.T.F.S.M. > > > -- > > Jorge Guerrero Damián > > Ingeniero Civil en Informática > > Egresado de Magister en Ciencias de la Ingeniería Informática > > U.T.F.S.M. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~----------~----~----~----~------~----~------~--~---