here is my error:
I am getting this error , can any one help me on this.
> SEVERE: Exception sending context initialized event to listener
> i
In my case, this error was due to the Network connection error that i was noticed in log.
This exception come due to you are providing listener ContextLoaderListener
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
but you are not providing context-param
for your spring configuration file. like applicationContext.xml
You must provide below snippet for your configuration
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>applicationContext.xml</param-value>
</context-param>
If You are providing the java based spring configuration , means you are not using xml file for spring configuration at that time you must provide below code:
<!-- Configure ContextLoaderListener to use AnnotationConfigWebApplicationContext
instead of the default XmlWebApplicationContext -->
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>
<!-- Configuration locations must consist of one or more comma- or space-delimited
fully-qualified @Configuration classes. Fully-qualified packages may also
be specified for component-scanning -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.nirav.modi.config.SpringAppConfig</param-value>
</context-param>
In my case, the error "BeanFactory not initialized or already closed - call 'refresh' before" was a consequence of a previous error that I didn't noticed in the server startup. I think that it is not always the real cause of the problem.
In my case, the error was valid and it was due to using try with resource
try (ConfigurableApplicationContext cxt = new ClassPathXmlApplicationContext(
"classpath:application-main-config.xml")) {..
}
It auto closes the stream which should not happen if I want to reuse this context in other beans.