1. 程式人生 > >BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the Appli

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

在做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>