Spring factory beans not always initialised before being used.

Posted by aos on Stack Overflow See other posts from Stack Overflow or by aos
Published on 2010-03-16T10:52:50Z Indexed on 2010/03/16 10:56 UTC
Read the original article Hit count: 387

Hi,

I am using spring to initialise my beans. I have configured a bean which I intend to use as a factory bean.

<bean id="jsServicesFactory" class="x.y.z.JSServicesFactory" />

It is a very basic class - which has 4 getter methods. One example is

 public final PortletRegistry getPortletRegistry() {
    PortletRegistry registry = (PortletRegistry) JetspeedPortletServices
        .getSingleton().getService("PortletRegistryComponent");
    return registry;
}

I have a 2nd bean which uses this factory beans to set one of its properties

<bean id="batchManagerService" class="x.y.z.BatchManagerService">
...
<property name="portletRegistry">
   <bean factory-bean="jsServicesFactory" factory-method="getPortletRegistry" />
</property>
     ...

When I start my server in RAD, this all works perfectly. However when I deploy to Linux I sometimes get the following error

ERROR org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'batchManagerService' defined in ServletContext resource [/WEB-INF/context/root/batchManagerContext.xml]: Cannot create inner bean 'jsServicesFactory$created#70be70be' while setting bean property 'portletRegistry'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jsServicesFactory$created#70be70be' defined in ServletContext resource [/WEB-INF/context/root/batchManagerContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public final org.apache.jetspeed.components.portletregistry.PortletRegistry x.y.z.JSServicesFactory.getPortletRegistry()] threw exception; nested exception is java.lang.NullPointerException

I have tried adding depends-on="jsServicesFactory" to my bean batchManagerService but it didn't work.

Any ideas?

Thanks

© Stack Overflow or respective owner

Related posts about spring-framework

Related posts about factory