Announcement Announcement Module
Collapse
No announcement yet.
Beans instantiating outside spring context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Beans instantiating outside spring context

    Hi
    I am trying to make an app where im using Hibernate, Spring and webservices (JWSDP).
    Now my problem is that when i call my webservice from a client, then it seems that an instance of one of my beans get constructed outside the spring context !!!

    I have set up the bean in the application context and can see that it is constructed at app startup by spring and gets all its dependencies injected correctly. But it is not the same bean i get later on when im constructing a new bean !!! Wich results in a nulll pointer in my app since the dependencies havent been injected !!!

    What am i doing wrong ???

    My web.xml looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    <display-name>LTD webservice</display-name>
    <description>
    blabla
    </description>
    <context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>ltd-server.root</param-value>
    </context-param>
    <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/log4j.properties</param-value>
    </context-param>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/spring/appContext.xml
    </param-value>
    </context-param>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>
    <listener>
    <listener-class>com.sun.xml.rpc.server.http.JAXRPCContextLis tener</listener-class>
    </listener>
    <servlet>
    <servlet-name>LokoService</servlet-name>
    <display-name>LokoService</display-name>
    <description>JAX-RPC endpoint - LokoService</description>
    <servlet-class>com.sun.xml.rpc.server.http.JAXRPCServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>LokoService</servlet-name>
    <url-pattern>/service</url-pattern>
    </servlet-mapping>
    <session-config>
    <session-timeout>30</session-timeout>
    <!-- 30 minutes -->
    </session-config>
    </web-app>

    My appcontext.xml looks like this :

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource" singleton="true">
    <property name="driverClassName">
    <value>oracle.jdbc.driver.OracleDriver</value>
    </property>
    <property name="url">
    <value>jdbc:oracle:thin:@ppdevdb2.dsb.dk:1527:LTDU DV</value>
    </property>
    <property name="username">
    <value>LTD</value>
    </property>
    <property name="password">
    <value>ltd</value>
    </property>
    </bean>
    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean" singleton="true">
    <property name="mappingResources">
    <list>
    <value>Lkf.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">net.sf.hibernate.dialect.O racle9Dialect</prop>
    <prop key="hibernate.cglib.use_reflection_optimizer">fal se</prop>
    </props>
    </property>
    <property name="dataSource">
    <ref bean="dataSource"/>
    </property>
    </bean>
    <bean id="lokoManDao" class="dk.dsb.ltd.dao.LokoManagerDao" singleton="true">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    </bean>
    <bean id="prodMan" class="dk.dsb.ltd.LokofoerServiceImpl" singleton="true" destroy-method="dispose" init-method="init">
    <property name="lokoManagerDao">
    <ref bean="lokoManDao"/>
    </property>
    </bean>
    </beans>

    The bean giving me all the problems is the one called prodMan...

    (I have a feeling that it might be the JAXRPC servlet that somehow is constructing the beans outside spring context)

    Id really appreciate some help here, any and all suggestions are welcome.

    Thanks
    Timm

  • #2
    Hi,

    what about placing some debug code in the default constructor of
    your LokofoerServiceImpl class (or just put a breakpoint there
    if you use a debugger).
    That code could simply do something like
    Thread.dumpstack();
    and you could see where the constructor is called from.

    Bye,
    Reinhard

    Comment


    • #3
      Possible solution

      I had a similar problem I had until I found an as-yet-unsubmitted fix to create Spring contexts within Axis (I am using Axis 1.1).

      I was able to integrate this and it is now working and solved a similar issue for me.

      Here is the URL:

      http://opensource.atlassian.com/proj...omponent=10020

      Comment


      • #4
        Great !!!
        Ill try and look at it. It seems like it is the same problem, though im not using axis.
        But maybe i can use some of it anyway.

        Thanks

        Comment

        Working...
        X