浏览 4212 次
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2007-03-19
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <servlet> <servlet-name>action</servlet-name> <servlet-class> org.apache.struts.action.ActionServlet </servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>3</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>3</param-value> </init-param> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <context-parame> <parame-name>contextConfigLocation</parame-name> <parame-value>/WEB-INF/applicationContext-hibernate.xml /WEB-INF/applicationContext-service.xml </parame-value> </context-parame> <lister> <lister-class> org.springframework.web.context.ContextLoaderListener </lister-class> </lister> <welcome-file-list> <welcome-file>use.jsp</welcome-file> </welcome-file-list> </web-app> 下面是我的一个baseAction在程序运行后的调用: package com.test.struts.action; import org.apache.commons.beanutils.BeanUtils; import org.apache.struts.actions.DispatchAction; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; public class BaseAction extends DispatchAction { ApplicationContext ur=null; public BaseAction() { super(); } public void copyProperties(Object to, Object from) throws Exception { BeanUtils.copyProperties(to, from); } public Object getBean(String name) { if (ur == null) { ur = WebApplicationContextUtils.getRequiredWebApplicationContext(servlet.getServletContext()); } return ur.getBean(name); } 但是在调用这个方法时就会出现如下错误: HTTP Status 500 - -------------------------------------------------------------------------------- type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: No WebApplicationContext found: no ContextLoaderListener registered? org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523) org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) javax.servlet.http.HttpServlet.service(HttpServlet.java:709) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) root cause java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered? org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:84) com.test.struts.action.BaseAction.getBean(BaseAction.java:24) com.test.struts.action.UseAction.execute(UseAction.java:44) org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106) org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) javax.servlet.http.HttpServlet.service(HttpServlet.java:709) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs. 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |