Java Spring ContextLoadListener错误

Java Spring ContextLoadListener错误,java,xml,spring,jsp,spring-mvc,Java,Xml,Spring,Jsp,Spring Mvc,我有一个运行正常的SpringMVC应用程序,我想在其中添加一个表单。然而,一旦我使用标记将表单添加到jsp中,我就开始得到一个找不到WebApplicationContext的结果:没有ContextLoaderListener注册?错误 我在这里进行了一些搜索,但我的web.xml文件中没有侦听器。我添加了最推荐的侦听器和上下文,但是随后我开始得到一个404请求的资源不可用错误。如果我将侦听器取出,那么我将返回到获取上一个错误。任何帮助都将不胜感激!相关代码如下: web.xml: ?xm

我有一个运行正常的SpringMVC应用程序,我想在其中添加一个表单。然而,一旦我使用标记将表单添加到jsp中,我就开始得到一个找不到WebApplicationContext的结果:没有ContextLoaderListener注册?错误

我在这里进行了一些搜索,但我的web.xml文件中没有侦听器。我添加了最推荐的侦听器和上下文,但是随后我开始得到一个404请求的资源不可用错误。如果我将侦听器取出,那么我将返回到获取上一个错误。任何帮助都将不胜感激!相关代码如下:

web.xml:

 ?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
         id="WebApp_ID" version="3.1">



  <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <display-name>Mic</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>spring-servlet.xml</param-value>
</context-param>

<!-- <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> -->

  <filter>
    <display-name>springSecurityFilterChain</display-name>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>
项目目录


您已经注释掉了您的

ContextLoaderListener


org.springframework.web.context.ContextLoaderListener

取消对它的注释,它就会工作。

在web.xml中,尝试以下操作:

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

春天
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
1.

您可以发布您的jsp吗?我已经添加了JSPP,请为异常提供完整的堆栈跟踪。但是,作为第一个提示,请尝试在
web.xml
中取消对
ContextLoaderListener
声明的注释,并确保在
web-INF
下提供一个(可能为空的)
applicationContext.xml
。我添加了在注释掉侦听器时获得的堆栈跟踪。当我取消对侦听器的注释时,我得到一个404 resource not found错误,并且没有堆栈跟踪。我将尝试添加一个空的applicationContext文件我想我已经找到了答案,我在玩Spring安全性,但从未完全实现它。我取出了web.xml中的所有spring安全引用,现在应用程序可以正常工作了。
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/includes.jsp"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>

<h1>Welcome to Mic</h1>

<a href="online">See who's online</a>

<form:form commandName="player">
  <form:input path="email" />

</form:form>


<c:forEach items="${whateve}" var="game">
    ${game.name}<br>

</c:forEach>

</body>
</html>
SEVERE: Servlet.service() for servlet [spring] in context with path [/Mic] threw exception
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:159)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>