Announcement Announcement Module
Collapse
No announcement yet.
Injecting Spring bean in Servlet Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Injecting Spring bean in Servlet

    Hello,

    Sorry for my bad english... ;-)

    I have a servlet that handles the communication with an applet. In the servlet I get my spring context and the bean userCarteCps like this:

    Code:
    ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
                UserCarteCps userCarteCps = (UserCarteCps)context.getBean("userCarteCps");
    I initializes the bean and then I go into my web app (struts 2) in the action identificationAction. The problem is that I get a bean userCarteCps that is not the same as the servlet and all property are null ... The bean is injected into the action identificationAction via the config file.

    ApplicationContext.xml:
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
        xmlns:oxm="http://www.springframework.org/schema/oxm"
        xsi:schemaLocation="
        http://www.springframework.org/schema/oxm 
        http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-2.5.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
     
     
        <context:component-scan base-package="com.enovation.dmp.beans" />
     
        <!-- Actions -->
        <bean id="creationDMPAction" class="com.enovation.dmp.action.CreationDMPAction">
            <property name="xmlService" ref="xmlService" />
            <property name="patientDMP" ref="patientDMP" />
            <property name="creationDMPService" ref="creationDMPService" />
            <property name="representantDMP" ref="representantDMP" />
            <property name="autorisationDMP" ref="autorisationDMP" />
            <property name="accesPatientDMP" ref="accesPatientDMP" />
            <property name="reponseDMP" ref="reponseDMP" />
            <property name="dmpCreation" ref="dmpCreation" />
            <property name="userCarteCps" ref="userCarteCps" />
        </bean>
     
        <bean id="lectureVitaleAction" class="com.enovation.dmp.action.LectureVitaleAction">
            <property name="userCarteCps" ref="userCarteCps" />
            <property name="xmlService" ref="xmlService" />
            <property name="dmpCreation" ref="dmpCreation" />
        </bean>
     
        <bean id="identificationAction" class="com.enovation.dmp.action.IdentificationAction">
            <property name="userCarteCps" ref="userCarteCps" />
            <property name="accesPatientDMP" ref="accesPatientDMP" />
            <property name="ldapService" ref="ldapService" />
     
        </bean>
     
        <!-- Services -->
        <bean id="xmlMapper" class="com.enovation.dmp.xml.impl.MapperXmlImpl">
            <property name="jaxbMarshaller" ref="jaxbMarshaller" />
        </bean>
     
        <bean id="ldapService" class="com.enovation.dmp.service.impl.LdapServiceImpl">
            <property name="userCarteCps" ref="userCarteCps" />
        </bean>
     
        <bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
            <property name="classesToBeBound">
                <array>
                    <value>com.enovation.dmp.beans.vitale.DonneesVitales</value>
                    <value>com.enovation.dmp.beans.DmpCreation</value>
                    <value>generated.EnfDmpCreation</value>
                </array>
            </property>
        </bean>
     
        <bean id="xmlService" class="com.enovation.dmp.service.impl.XmlServiceImpl">
            <property name="xmlMapper" ref="xmlMapper" />
            <property name="patientDMP" ref="patientDMP" />
            <property name="coordonneesVitale" ref="coordonneesVitale" />
        </bean>
     
        <bean id="creationDMPService" class="com.enovation.dmp.service.impl.CreationDMPServiceImpl">
            <property name="xmlMapper" ref="xmlMapper" />
            <property name="dmpCreation" ref="dmpCreation" />
            <property name="wsCreationDMP" ref="wsCreationDMP" />
            <property name="reponseDMP" ref="reponseDMP" />
            <property name="accesPatientDMP" ref="accesPatientDMP" />
        </bean>
     
        <!-- BEANS -->
        <bean id="userCarteCps" class="com.enovation.dmp.beans.UserCarteCps"
     
            scope="session">
            <aop:scoped-proxy />
        </bean>
        <bean id="dmpCreation" class="com.enovation.dmp.beans.DmpCreation"
     
            scope="session">
            <aop:scoped-proxy />
            <property name="patient" ref="patientDMP" />
            <property name="representant" ref="representantDMP" />
            <property name="autorisations" ref="autorisationDMP" />
            <property name="vitale" ref="coordonneesVitale" />
            <property name="auteur" ref="userCarteCps" />
            <property name="accesPatient" ref="accesPatientDMP" />
            <property name="reponse" ref="reponseDMP" />
        </bean>
        <bean id="accesPatientDMP" class="com.enovation.dmp.beans.AccesPatientDMP"
     
            scope="session">
            <aop:scoped-proxy />
        </bean>
        <bean id="reponseDMP" class="com.enovation.dmp.beans.ReponseDMP"
     
            scope="session">
            <aop:scoped-proxy />
        </bean>
        <bean id="patientDMP" class="com.enovation.dmp.beans.PatientDMP"
     
            scope="session">
            <aop:scoped-proxy />
        </bean>
        <bean id="representantDMP" class="com.enovation.dmp.beans.RepresentantDMP"
     
            scope="session">
            <aop:scoped-proxy />
        </bean>
        <bean id="autorisationDMP" class="com.enovation.dmp.beans.AutorisationDMP"
     
            scope="session">
            <aop:scoped-proxy />
        </bean>
        <bean id="coordonneesVitale" class="com.enovation.dmp.beans.CoordonneesVitale"
     
            scope="session">
            <aop:scoped-proxy />
        </bean>
     
    </beans>
Working...
X