No WebApplicationContext found: no ContextLoaderListener registered錯誤

運行結果報錯:
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext
org.springframework.web.struts.DelegatingActionUtils.findRequiredWebApplicationContext(java:148)
org.springframework.web.struts.DelegatingActionProxy.getWebApplicationContext(java:139)
org.springframework.web.struts.DelegatingActionProxy.getDelegateAction(DelegatingActionProxy.java:120)
org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:105)
org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

方法一: 
第一:發現原來是他的配置文件不是放在WEB-INF下,而是放在src目錄下,解決的方法可將其spring的配置文件applicationContext轉移陣地,轉到WEB-INF下,或在web.xml下加入如下語句: 
<!-- Spring ApplicationContext配置文件的路徑,可使用通配符,多個路徑用,號分隔此參數用於後面的Spring-Context loader --> 

<context-param> 

<param-name>contextConfigLocation</param-name> 

<param-value>/WEB-INF/applicationContext*.xml,classpath*:applicationContext*.xml</param-value> 

</context-param> 

第二:在web.xml裏面加上樓上說的 
<listener> 
<listener-class> 
org.springframework.web.context.ContextLoaderListener 
</listener-class> 
</listener> 
發佈了22 篇原創文章 · 獲贊 1 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章