使用shiro 框架 报错No WebApplicationContext found: no ContextLoaderListener or DispatcherServlet registered?

1、问题描述:ssm 框架中使用shiro  中出现问题

原来web.xml 文件如下:

<!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1" metadata-complete="true">
  <display-name>Archetype Created Web Application</display-name>

    <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!-- 配置springMVC需要加载的配置文件
        spring-dao.xml,spring-service.xml,spring-mvc.xml
        Mybatis - > spring -> springmvc
     -->
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring/spring-*.xml</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <!-- 默认匹配所有的请求 -->
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <!-- 编码过滤器-->
  <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>utf-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!-- 项目欢迎页面-->
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>


  <!-- 基本知识: 现在在下面配置好过滤器的名字 + 哪些url 会进入当前的过滤器 -->
  <!--过滤器:  你先配置一个过滤器 ,后配置一个过滤器, 那么url 就会先进入一个过滤器, 然后再进入另外一个过滤器 -->
  <!-- shiro 为什么自己有一个过滤器呢:因为shiro框架是有做安全登录方面的功能实现的,所以他有一个自己的过滤器, 来对url进行过滤 -->
  <!-- 如果没有自己的一个过滤器, 如何实现用户的验证授权等等-->
  <!-- shiro的过滤器 -->
  <filter>
    <filter-name>shiroFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>shiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

运行tomcat 显示报错如下:

 

2、解决方案:

 然后对web.xml 进行修改,增加了下面红色的字体的内容, 解决问题

<!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1" metadata-complete="true">
  <display-name>Archetype Created Web Application</display-name>

    <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!-- 配置springMVC需要加载的配置文件
        spring-dao.xml,spring-service.xml,spring-mvc.xml
        Mybatis - > spring -> springmvc
     -->
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring/spring-*.xml</param-value>
    </init-param>
      <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <!-- 默认匹配所有的请求 -->
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <!-- 编码过滤器-->
  <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>utf-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!-- 项目欢迎页面-->
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>


  <!-- 基本知识: 现在在下面配置好过滤器的名字 + 哪些url 会进入当前的过滤器 -->
  <!--过滤器:  你先配置一个过滤器 ,后配置一个过滤器, 那么url 就会先进入一个过滤器, 然后再进入另外一个过滤器 -->
  <!-- shiro 为什么自己有一个过滤器呢:因为shiro框架是有做安全登录方面的功能实现的,所以他有一个自己的过滤器, 来对url进行过滤 -->
  <!-- 如果没有自己的一个过滤器, 如何实现用户的验证授权等等-->
  <!-- shiro的过滤器 -->
  <filter>
    <filter-name>shiroFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>shiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

3、问题探究:

报错信息里面显示:No WebApplicationContext found: no ContextLoaderListener or DispatcherServlet registered?

https://blog.csdn.net/zuoyexingchennn/article/details/50426869

https://www.cnblogs.com/JesseV/archive/2009/11/17/1605015.html

https://blog.csdn.net/Thousa_Ho/article/details/78464932

这三篇文章,应该是可以解决上面问题的原因, 但是我现在是个渣渣辉, 看不懂

原文地址:https://www.cnblogs.com/helloqiufei/p/11653751.html