首页 > 解决方案 > 访问控制器映射的 URL 差异

问题描述

我正在尝试学习Spring FrameworkSpring MVC并且Spring Boot REST在创建一个虚拟项目时,我注意到浏览器中Tomcat响应您的方式的差异如下URL

弹簧靴

http://localhost:8080/

Redirects to the Controller that is mapped to "/"

http://localhost:8080/springbootrestapp

where "springbootrestapp" is the project name, it gives HTTP 404 resource not found error

春季MVC

http://localhost:8080/

Opens the Tomcat Home page

http://localhost:8080/springmvc

where "springmvc" is the project name, it redirects to the Controller that is mapped to "/"

我的疑问是,为什么Spring Boot只是输入localhost:8080重定向到controller映射到"/"的情况,而在Spring MVC(没有 Spring Boot 配置)的情况下,它需要http://localhost:8080/<projectname>/重定向到controller映射到"/"

标签: javaspringspring-bootspring-mvc

解决方案


我遇到了同样的问题在我的情况下,在运行我的 Spring-MVC 应用程序之前,我启动了我没有停止的 tomcat 服务器,所以每当我访问 localhost:8080/ 时,它都会将我重定向到 Tomcat 客户端。


推荐阅读