具体报错:
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:177)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1057)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1026)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:975)
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:517)
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4980)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5626)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Maven项目中启动tomcat出现这种问题有很多人刚开始还不知道怎么回事,怎么检查发现自己代码都没问题,该编译的文件都编译进target了。maven中启动tomacat运行发现还是运行时报错,这时候一定要注意:先把target文件删除了,再编译,一定要先编译后再在maven中启动tomcat运行,也就是先点下面这个:
这样做的话应该就能完美解决了