Spring MVC + Eclipse:HTTP 404 – 未找到

Posted

技术标签:

【中文标题】Spring MVC + Eclipse:HTTP 404 – 未找到【英文标题】:Spring MVC + Eclipse: HTTP 404 – Not Found 【发布时间】:2021-05-17 21:06:21 【问题描述】:

问题总结

我在 Eclipse 中创建了一个基本的 Spring MVC 应用程序,并手动将 Spring JAR 添加到了库中。我正在使用 XML 配置。当我运行它时它返回一个 404 错误。我控制台中的 WARN 输出告诉我 WARNING: No mapping for GET /Spring-MVC-Demo/

我尝试过的

    我的 web.xml 文件具有 <absolute-ordering /> 标记,正如其他类似问题的答案中所建议的那样。

    我还更新了 <context:component-scan base-package="com.demo.springdemo.mvc" /> 以反映我自己的 src 包名称,正如在另一个类似问题的答案中所建议的那样。

我知道控制台 WARN 非常明确地告诉我出了什么问题,但我只是不知道如何解决它。

这里是源代码

https://drive.google.com/drive/folders/1GTuRmBdIugvQT-8OxW4g-EcdHdRAsj49?usp=sharing

控制台输出:

Feb 14, 2021 8:43:49 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version name:   Apache Tomcat/9.0.43
Feb 14, 2021 8:43:50 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Jan 28 2021 20:25:45 UTC
Feb 14, 2021 8:43:50 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version number: 9.0.43.0
Feb 14, 2021 8:43:50 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Windows 10
Feb 14, 2021 8:43:50 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            10.0
Feb 14, 2021 8:43:50 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Feb 14, 2021 8:43:50 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             C:\Program Files\Java\jre1.8.0_271
Feb 14, 2021 8:43:50 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_271-b09
Feb 14, 2021 8:43:50 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Feb 14, 2021 8:43:50 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         C:\Users\odubh\Workspace_Eclipse\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Feb 14, 2021 8:43:50 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         C:\Program Files\Apache Software Foundation\Tomcat 9.0
Feb 14, 2021 8:43:50 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\Users\odubh\Workspace_Eclipse\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Feb 14, 2021 8:43:50 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 9.0
Feb 14, 2021 8:43:50 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\Users\odubh\Workspace_Eclipse\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Feb 14, 2021 8:43:50 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 9.0\endorsed
Feb 14, 2021 8:43:50 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
Feb 14, 2021 8:43:50 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: Loaded Apache Tomcat Native library [1.2.26] using APR version [1.7.0].
Feb 14, 2021 8:43:50 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
Feb 14, 2021 8:43:50 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
Feb 14, 2021 8:43:50 PM org.apache.catalina.core.AprLifecycleListener initializeSSL
INFO: OpenSSL successfully initialized [OpenSSL 1.1.1i  8 Dec 2020]
Feb 14, 2021 8:43:50 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Feb 14, 2021 8:43:50 PM org.apache.catalina.startup.Catalina load
INFO: Server initialization in [948] milliseconds
Feb 14, 2021 8:43:50 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Catalina]
Feb 14, 2021 8:43:50 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet engine: [Apache Tomcat/9.0.43]
Feb 14, 2021 8:43:51 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Feb 14, 2021 8:43:51 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring DispatcherServlet 'dispatcher'
Feb 14, 2021 8:43:51 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: Initializing Servlet 'dispatcher'
Feb 14, 2021 8:43:52 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: Completed initialization in 1335 ms
Feb 14, 2021 8:43:52 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Feb 14, 2021 8:43:52 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in [2323] milliseconds
Feb 14, 2021 8:43:53 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping for GET /Spring-MVC-Demo/

版本

Tomcat:9.0

日食:2020-12 (4.18.0)

JDK:1.8.0_271

【问题讨论】:

【参考方案1】:

我的“main-menu.jsp”命名有误。我不小心把它叫做“main-manu.jsp”。除了说检查文件名的拼写之外,这个问题可能对任何人都没有用。

【讨论】:

您可以编辑之前的消息。并删除这个。

以上是关于Spring MVC + Eclipse:HTTP 404 – 未找到的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Eclipse 中创建 Spring MVC 项目?

eclipse使用maven搭建spring mvc

Spring MVC HelloWorld

你如何在Eclipse中创建一个Spring MVC项目?

带有 Spring Boot 的 Spring MVC 不适用于 Eclipse 的 Tomcat 服务器

Eclipse错误