日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

SpringMVC——訪問action報404錯誤詳解

作者:xinlianluohan 更新時間: 2023-12-13 編程語言

1、檢查URL是否會被springmvc攔截

首先檢查訪問路徑URL是否正確被springmvc攔截,這個URL和web.,xml中對springmvc的配置有關。

2、檢查Controller層是否使用@Controller注解

檢查是否在Controll層使用@Controller注解來將其標注為組件;

只有使用了@Controller標注的Controller層才能被Springmvc識別.

3、檢查是否配置了<context:component-scan/><mvc:annotation-driven/>(springmvc.xml中)

3.1、檢查是否配置了<context:component-scan/>
????????1、<context:component-scan/>是用來指明讓springmvc容器去哪里掃描@Controller注解,只有springmvc找到了@Controller注解,springmvc才能進入Controller.

????????2、配置方式為:<context:component-scan base-package="com.taotao.controller" />?

3.2、檢查<context:component-scan/>是否配置正確
????????1、Base-package后面如果寫成”com.taotao.controller.*”是錯誤的(不帶*,定位到包即可).

????????2、Base-package后面的路徑指的是Controller層所在的包,如圖,注意路徑一定要寫對.

3.3、檢查是否配置了<mvc:annotation-driven/>
<mvc:annotation-driven/>相當于注冊了DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter兩個bean,配置一些messageconverter。即解決了@Controller注解的使用前提配置。配置方式為:<mvc:annotation-driven />

ps:<mvc:annotation-driven/>和<context:component-scan/>不分先后順序

4、檢查是否正確讀取Springmvc的配置文件(web.xml中)

4.1、如果沒有配置<init-param></init-param>
????????那么spring容器會自動去WEB-INF目錄下掃描一個叫SpringMVC-servlet.xml的配置文件來加載springmvc容器.

4.2、如果如下圖配置了<init-param></init-param>
????????重點檢查一下是否classpath后面的路徑書寫的有錯誤.

注意:

????????1.只有成功讀取到springmvc的xml配置文件,才能讓spring容器加載springmvc容器,然后才能識別@Controller注解并執行標注的Contoller層

????????2.<param-name></param-name>之間的contextConfigLocation是固定的


PS:

web.xml加載spring容器的xml配置文件時,<param-name></param-name>之間的contextConfigLocation也是固定的.

5、檢查是否成功加載spring容器

如果spring容器都未成功加載,那么肯定無法成功加載springmvc容器。

5.1、檢查spring容器的監聽是否正常啟動

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


5.2、檢查是否正確讀取了spring容器的xml配置文件
??

注意:再次強調,<param-name>標簽中的contextConfigLocation是固定的,書寫錯誤會報錯

原文鏈接:https://gaodengwen.blog.csdn.net/article/details/132713697

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新