You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jens Borgland <je...@gmail.com> on 2012/02/08 17:58:27 UTC

Refreshing the Spring context leads to NPE

Hi,

I have a web application that uses Spring and CXF (currently 2.4.2),
and runs on Tomcat.

The application (not just CXF) is initialized using the
org.springframework.web.context.ContextLoaderListener.

Starting and shutting the application down works like a charm but if I
try to refresh the Spring application context, using
((ConfigurableApplicationContext)applicationContext).refresh(); I run
into problems. The application context first destroys all its beans
(including CXFBusImpl, or rather its subclass SpringBus). SpringBus
however calls close() on its application context - leading to a
NullPointerException when the application context shortly after tries
to close its bean factory:

java.lang.NullPointerException
    at org.springframework.context.support.AbstractRefreshableApplicationContext.closeBeanFactory(AbstractRefreshableApplicationContext.java:152)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:124)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)

What can I do to avoid this? I don't really understand why CXFBusImpl
should close the context in the first place?

Best regards,
Jens

Re: Refreshing the Spring context leads to NPE

Posted by Jens Borgland <je...@gmail.com>.
Hi,

Thanks but I just tried both 2.4.6 and 2.5.2 with the same result.

Looking at the source code, SpringBus still calls ctx.close() in its
destroyBeans() method, which I think it shouldn't. I just tried commenting
out that row and rebuilding CXF which made my scenario work (as well as
normal startup and shutdown). I guess I'll file a bug for this.
Jens
2012/2/8 Daniel Kulp <dk...@apache.org>

> On Wednesday, February 08, 2012 5:58:27 PM Jens Borgland wrote:
> > Hi,
> >
> > I have a web application that uses Spring and CXF (currently 2.4.2),
> > and runs on Tomcat.
>
> I would definitely try a newer version of CXF.  Many fixes were put in
> place
> to help handle various lifecycle issues with the Bus and the contexts
> (spring
> and blueprint) so this issue may already be fixed.
>
> Dan
>
>
> >
> > The application (not just CXF) is initialized using the
> > org.springframework.web.context.ContextLoaderListener.
> >
> > Starting and shutting the application down works like a charm but if I
> > try to refresh the Spring application context, using
> > ((ConfigurableApplicationContext)applicationContext).refresh(); I run
> > into problems. The application context first destroys all its beans
> > (including CXFBusImpl, or rather its subclass SpringBus). SpringBus
> > however calls close() on its application context - leading to a
> > NullPointerException when the application context shortly after tries
> > to close its bean factory:
> >
> > java.lang.NullPointerException
> >     at
> >
> org.springframework.context.support.AbstractRefreshableApplicationContext.c
> > loseBeanFactory(AbstractRefreshableApplicationContext.java:152) at
> >
> org.springframework.context.support.AbstractRefreshableApplicationContext.r
> > efreshBeanFactory(AbstractRefreshableApplicationContext.java:124) at
> >
> org.springframework.context.support.AbstractApplicationContext.obtainFreshB
> > eanFactory(AbstractApplicationContext.java:467) at
> >
> org.springframework.context.support.AbstractApplicationContext.refresh(Abst
> > ractApplicationContext.java:397)
> >
> > What can I do to avoid this? I don't really understand why CXFBusImpl
> > should close the context in the first place?
> >
> > Best regards,
> > Jens
> --
> Daniel Kulp
> dkulp@apache.org - http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
>

Re: Refreshing the Spring context leads to NPE

Posted by Daniel Kulp <dk...@apache.org>.
On Wednesday, February 08, 2012 5:58:27 PM Jens Borgland wrote:
> Hi,
> 
> I have a web application that uses Spring and CXF (currently 2.4.2),
> and runs on Tomcat.

I would definitely try a newer version of CXF.  Many fixes were put in place 
to help handle various lifecycle issues with the Bus and the contexts (spring 
and blueprint) so this issue may already be fixed.

Dan


> 
> The application (not just CXF) is initialized using the
> org.springframework.web.context.ContextLoaderListener.
> 
> Starting and shutting the application down works like a charm but if I
> try to refresh the Spring application context, using
> ((ConfigurableApplicationContext)applicationContext).refresh(); I run
> into problems. The application context first destroys all its beans
> (including CXFBusImpl, or rather its subclass SpringBus). SpringBus
> however calls close() on its application context - leading to a
> NullPointerException when the application context shortly after tries
> to close its bean factory:
> 
> java.lang.NullPointerException
>     at
> org.springframework.context.support.AbstractRefreshableApplicationContext.c
> loseBeanFactory(AbstractRefreshableApplicationContext.java:152) at
> org.springframework.context.support.AbstractRefreshableApplicationContext.r
> efreshBeanFactory(AbstractRefreshableApplicationContext.java:124) at
> org.springframework.context.support.AbstractApplicationContext.obtainFreshB
> eanFactory(AbstractApplicationContext.java:467) at
> org.springframework.context.support.AbstractApplicationContext.refresh(Abst
> ractApplicationContext.java:397)
> 
> What can I do to avoid this? I don't really understand why CXFBusImpl
> should close the context in the first place?
> 
> Best regards,
> Jens
-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com