You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

跳转落地控制器时DispatcherServlet找不到HTTP请求URI映射问题求助

问题原因

  • 缺失MVC注解驱动配置:你的mvc-dispatcher-servlet.xml只开启了组件扫描,没有配置<mvc:annotation-driven />,SpringMVC无法识别@RequestMapping注解的请求映射规则,这是直接导致404的核心原因。
  • 容器配置冲突:DispatcherServlet默认会自动加载/WEB-INF/mvc-dispatcher-servlet.xml作为Servlet子容器的配置,你同时将该路径配置给了根容器ContextLoaderListener,父子容器重复加载同一份配置可能导致Bean注册异常。

修复步骤

  1. 修改mvc-dispatcher-servlet.xml,添加mvc命名空间和注解驱动配置,修改后完整配置如下:
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <context:component-scan base-package="com.microsoft.aad.adal4jsample" />
    <mvc:annotation-driven />
    
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>
  1. 调整web.xml配置,如果你没有单独的根容器Bean(如Service、DAO层Bean)配置,直接删除context-param和ContextLoaderListener配置即可,修改后web.xml如下:
<?xml version="1.0"?>
<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>
  1. 路径验证:你当前控制器的@RequestMapping("/jsp/MyClientControllerServlet")配置和请求路径匹配,无需调整,视图解析器的前后缀配置也和路径规则兼容,只要方法返回的视图名正确即可正常跳转。

补充:如果修改后仍然报错,可将启动日志级别调成DEBUG,查看com.microsoft.aad.adal4jsample.AadController是否被正常注册为Bean,以及请求映射规则是否被加载。


内容的提问来源于stack exchange,提问作者vick_4444

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.21 08:15:04