tags:

views:

28

answers:

1

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

A: 

The clue is in the stack trace, albeit buried deep in it:

nested exception is java.lang.NullPointerException

Something in your code is throwing a NPE during initialization of the beans, and this is propagating up the stack, being re-wrapped in other exceptions as it goes.

Find the root cause of that NPE, and that should fix the problem.

skaffman
Hi, thank you for your feedback. I believe the NPE is that the jsServicesFactory is still not initialised before it is used and therefore throws a NPE. However just to be sure I have added logging to method getPortletRegistry(). I will redeploy to Linux and let you know the outcome. Thank you
aos
Hello,I have tested this again with log messages (all I added was log messages, nothing else) and I don't get any error this time. Which makes me think that this is a timing issue or something like that?
aos
@aos Very likely, yes, but I maintain that it's a NullPointerException within your own code that's triggering cascading exceptions from Spring.
skaffman
Thank you - you were correct. I was trying to access services in the portal however the portal had not fully come online.
aos