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

版权声明:博客知识产权来源命运的信徒,切勿侵权 https://blog.csdn.net/qq_37591637/article/details/85318510

在做Spring整合Struts2的时候,启动项目,就报了如下的错误

Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener

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

java.io.FileNotFoundException: Could not open ServletContext resource [/applicationContext.xml]


背景:

我是在xml文件中配置ioc容器,在jsp页面采用<%%>的形式调用实例


第一个错误:

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

原因:

是配置文件的名称是contextConfigLocation,一点都不能错!!!!!


第二个错误:

java.io.FileNotFoundException: Could not open ServletContext resource [/applicationContext.xml]

原因:

是地址不对 

应该是<param-value>classpath:applicationContext.xml</param-value>


正确的配置文件应该如下:

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

猜你喜欢

转载自blog.csdn.net/qq_37591637/article/details/85318510