Am trying to also use spring for dependency injection in GWT server-
side functionality.

using this class (application context file locations hard-coded in
this example)

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 Arnaud Louet
 */
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

        }
}

The application context file is referenced from a file named
beanRefFactory.xml this file refers to the main application context:

<?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>

contents of 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>

finally the code for the service implementation (where the beans are
injected)

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;

        @Override
        public void init() throws ServletException {
                super.init();   //To change body of overridden methods use File 
|
Settings | File Templates.
        }

        public SampleServiceImpl() {
                super();
        }

        public String getCurrentTime() {
                return myBean.getCurrentTimeAsString();
        }

}






On Feb 12, 6:29 pm, Christoph <[email protected]> wrote:
> 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 <[email protected]>
> 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 <[email protected]>
>
> > > 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.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to