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

  • Beans instantiating outside spring context

    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" "">
    <display-name>LTD webservice</display-name>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    <listener-class>com.sun.xml.rpc.server.http.JAXRPCContextLis tener</listener-class>
    <description>JAX-RPC endpoint - LokoService</description>
    <!-- 30 minutes -->

    My appcontext.xml looks like this :

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "">
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource" singleton="true">
    <property name="driverClassName">
    <property name="url">
    <value> DV</value>
    <property name="username">
    <property name="password">
    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean" singleton="true">
    <property name="mappingResources">
    <property name="hibernateProperties">
    <prop key="hibernate.dialect">net.sf.hibernate.dialect.O racle9Dialect</prop>
    <prop key="hibernate.cglib.use_reflection_optimizer">fal se</prop>
    <property name="dataSource">
    <ref bean="dataSource"/>
    <bean id="lokoManDao" class="" singleton="true">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    <bean id="prodMan" class="" singleton="true" destroy-method="dispose" init-method="init">
    <property name="lokoManagerDao">
    <ref bean="lokoManDao"/>

    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.


  • #2

    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
    and you could see where the constructor is called from.



    • #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:


      • #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.