BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ...

搭建SSM项目过程,在tomcat启动时报错,报错信息:

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:172)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1071)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1045)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:993)
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:548)
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:142)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:5050)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5712)
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.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:677)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1912)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at java.lang.Thread.run(Thread.java:745)


web.xml配置文件:


xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
id="WebApp_ID" version="3.0"> 
  SSM
  
   

 
 
  characterEncoding
  org.springframework.web.filter.CharacterEncodingFilter
 
  encoding
  UTF-8
 

 

 
  characterEncoding
  /*
 

  
 
 
  contextConfigLocation
  applicationContext.xml
 

 
  org.springframework.web.context.ContextLoaderListener
 

  
 
 
  struts2
  org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
 
 

 
  struts2
  /*
 

  
 
   log4jConfigLocation
   /WEB-INF/log4j.properties
 




 
org.springframework.web.util.Log4jConfigListener
 


  
 
    index.jsp
 

  


--------------------------------------------------------------------------------------

根据报错信息翻译过来:在类工厂未被实例化或已被关闭-- 在通过applicationcontent进入beans之前刷新(个人自行翻译,理解为主) 推断应该是spring文件读取的问题,首先检查配置路径:

BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ..._第1张图片

BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ..._第2张图片


BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ..._第3张图片


项目的一些信息

 解决:

 
 
  contextConfigLocation
  classpath:applicationContext.xml
 

 
  org.springframework.web.context.ContextLoaderListener

 


路径前:添加classpath


ps.classpath 与classpath*:区别:

https://www.cnblogs.com/Ant-soldier/p/5474085.html



你可能感兴趣的:(Java开发)