错误:没有注册ContextLoaderListener

时间:2013-01-24 04:28:10

标签: spring-mvc

嗨我已经在spring mvc中编写了登录代码,我的代码如下:

web.xml中: -

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd“id =”WebApp_ID“version =”2.5“>   Spring3Demo

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/forms/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
 </web-app>

分配器一小服务程序: -

<context:component-scan base-package="net.roseindia.controllers" />

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/views/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="/WEB-INF/messages" />
</bean>
<bean id="loginForm" class="net.roseindia.forms.LoginValidator"/>
<bean id="loginController" class="net.roseindia.controllers.LoginController">
    <property name="sessionForm"><value>false</value></property>
    <property name="commandName"><value>loginForm</value></property>
    <property name="commandClass"><value>net.roseindia.forms.LoginForm</value></property>
    <property name="formView"><value>index</value></property>
    <property name="successView"><value>loginsuccess</value></property>
    <property name="urlMap">
        <map>
            <entry key="index.jsp">
                <ref bean="loginController"/>
            </entry>
        </map>
    </property>
</bean>
<!-- Configure the multipart resolver -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">      
</bean>

Index.jsp: - 这是webinf中的网络内容文件夹

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>Spring 3, MVC Examples</title>
</head>
 <body>
    <h1>Spring 3, MVC Examples</h1>
 <ul>
   <li><a href="forms/helloworld.html">Hello World</a></li>
</ul>
<form:form action="login.html" commandName="loginForm"  >
<table>
    <tr>
    <td>User Name<FONT color="red"><form:errors path="userName" /></FONT></td>  <td><form:input path="userName" /></td>
    </tr>
    <tr>
    <td>Password<FONT color="red"><form:errors path="password" /></FONT></td><td><form:password path="password" /></td>
    </tr>
    <tr>
    <td colspan="2"><input type="submit" name="submit" value="Login"/></td>
    </tr>
</table>
</form:form>
  </body>
</html>

在src文件夹中我有类 net.roseindia.forms.LoginForm net.roseindia.controllers.LoginController

我收到错误java.lang.IllegalStateException:找不到WebApplicationContext:没有注册ContextLoaderListener?  在index.jsp i的第15行。即在表格标签上

plz建议如何配置它。

1 个答案:

答案 0 :(得分:1)

将上下文参数contextConfigLocation添加到web.xml。即使您不需要尝试添加空的applicationContext文件。

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath*:applicationContext*.xml</param-value> 
</context-param>