BeanFactory not initialized or already closed - call 'refresh' before

后端 未结 10 1562
無奈伤痛
無奈伤痛 2020-12-10 01:23

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         


        
相关标签:
10条回答
  • 2020-12-10 01:44

    In my case, this error was due to the Network connection error that i was noticed in log.

    0 讨论(0)
  • 2020-12-10 01:47

    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>
    
    0 讨论(0)
  • 2020-12-10 01:47

    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.

    0 讨论(0)
  • 2020-12-10 01:47

    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.

    0 讨论(0)
提交回复
热议问题