使用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

 

這三篇文章,應該是可以解決上面問題的原因, 但是我現在是個渣渣輝, 看不懂

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM