论坛首页 入门技术论坛

applicationContext.xml在Web.xml中启动时不能初始化的一个大问题!请指教!

浏览 4213 次
该帖已经被评为新手帖
作者 正文
   发表时间:2007-03-19  
这是我的web.xml配置文件如下:
<?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.

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics