springmvc 请求无法到达controller,出现404

今天在配置SpringMVC时,访问项目一直出现404,无法访问。

报错:

The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

调试了一下,发现没有到达controller层里面。

运行后没有到达controller层的解决方法:

1.检查web.xml文件中的SpringMVC的配置是否正确。

  <!-- Spring MVC servlet -->
    <servlet>
        <servlet-name>SpringMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <!--<init-param>表示启动时初始化的配置文件-->
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <!--<servlet-mapping>中的</servlet-name>必须与<servlet>里面的<servlet-name>保持一致-->
        <servlet-name>SpringMVC</servlet-name>
        <!-- 一般定义为 / ,表示所有请求都通过DispatcherServlet来处理-->
        <url-pattern>/</url-pattern>
    </servlet-mapping>

2.检查spring-mvc.xml,是否添加了注解驱动

    <!--注解驱动-->
    <mvc:annotation-driven/>

猜你喜欢

转载自www.cnblogs.com/expiator/p/9284237.html