spring项目启动报错BeanFactory not initialized or already closed

Posted 精灵lc

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring项目启动报错BeanFactory not initialized or already closed相关的知识,希望对你有一定的参考价值。

spring项目启动的时候报如下错误:

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:4011)
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4615)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4512)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
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:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

我的解决方法:在web.xml中加入如下的就可以正常启动了

 

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/applicationContext.xml
</param-value>
</context-param>




























以上是关于spring项目启动报错BeanFactory not initialized or already closed的主要内容,如果未能解决你的问题,请参考以下文章

Spring--简记

Spring启动注册BeanFactory后置处理器

SpringBoot:Spring容器的启动过程

BeanFactory not initialized or already closed exception

Spring源码解读---启动过程源码解析

Spring源码解读---启动过程源码解析