Spring Bean Factory Exception : BeanFactory not initialized or already closed

The given exception is exception is thrown when the spring bean factory is not initialized properly before it is used in your application. It normally occurs when we are not added the bean factory initialization code in our project. One typical example is adding the spring initialization parameter to web.xml deployment descriptor.

<context-param>
	<param-name>contextConfigLocation</param-name>
	<param-value>\WEB-INF\dispatcher-servlet.xml</param-value>
</context-param>
<listener>
	<listener-class>
		org.springframework.web.context.ContextLoaderListener
	</listener-class>
</listener>

Exception Trace:

SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
	at org.springframework.context.support.AbstractRefreshableApplicationContext.
getBeanFactory(AbstractRefreshableApplicationContext.java:171)
	at org.springframework.context.support.AbstractApplicationContext.
destroyBeans(AbstractApplicationContext.java:1090)
	at org.springframework.context.support.AbstractApplicationContext.
doClose(AbstractApplicationContext.java:1064)
	at org.springframework.context.support.AbstractApplicationContext.
close(AbstractApplicationContext.java:1010)
	at org.springframework.web.context.ContextLoader.
closeWebApplicationContext(ContextLoader.java:559)
	at org.springframework.web.context.ContextLoaderListener.
contextDestroyed(ContextLoaderListener.java:143)
	at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:3973)
	at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4577)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4474)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
	at org.apache.catalina.core.StandardService.start(StandardService.java:516)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Pin It on Pinterest

Share This

Share this post with your friends!

Share This

Share this post with your friends!