描述你的问题
使用了Spring MVC 框架
使用jetty-maven-plugin插件运行可以运行正常访问({"/"})路径(就是http://localhost:8080/),然而maven打包放到tomcat的ROOT目录访问({"/"})出现404,启动日志有显示已经映射({"/"})路径
贴上相关代码
HomeController.java
@Controller
public class HomeController {
@RequestMapping("/")
public String index(){
return "index";
}
}
web.xml
fly
contextConfigLocation
classpath*:/applicationContext.xml
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
encodingFilter
/*
org.springframework.web.context.ContextLoaderListener
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath*:/springmvc-servlet.xml
1
true
springmvc
/
404
/static/errors/404.html
500
/static/errors/50x.html
pom.xml
1.7.5
1.0.13
4.2.2.RELEASE
1.2.2
2.2.2
org.mybatis.generator
mybatis-generator-maven-plugin
1.3.2
true
true
org.eclipse.jetty
jetty-maven-plugin
9.2.10.v20150310
1
8888
1
manual
org.apache.maven.plugins
maven-compiler-plugin
1.8
1.8
UTF-8
贴上报错信息
启动
08-Feb-2016 18:01:04.732 INFO [localhost-startStop-1] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.register Mapped "{[/]}" onto public java.lang.String me.zonghua.fly.HomeController.index()
访问
08-Feb-2016 17:45:14.136 WARNING [http-nio-8080-exec-1] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/] in DispatcherServlet with name 'springmvc'
贴上相关截图
使用jetty运行

使用tomcat运行,这是指定的404页面
已经尝试过哪些方法仍然没解决(附上相关链接)
除了({"/"})路径外,其他页面访问都是正常的。
此问题Google无果,不知道是不是Spring MVC 4.2.2.RELEASE 的问题
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
把servlet中name为springmvc的url-pattern的/改成/*
查看tomcat的server.xml中该项目的Context path,比如<Context path="/myapp" .../> 那么url里头就是localhost:8080/myapp
参考官方的实例
web.xml要写成不然不能匹配 [/] 路径
虽然另外一个工程中写成
也能访问