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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章