Spring mvc应用程序在tomcat中不起作用,但它在IDE中运行良好

时间:2013-09-02 14:10:05

标签: spring spring-mvc tomcat7 apache-tiles

请帮我弄清楚这个奇怪的行为,我有一个基于Spring的项目https://github.com/riuvshin/spring-mvc-learn,我想部署* .war到tomcat 7.0。当我根据日志部署那个战争来清理tomcat它应该可以正常工作,但是当我尝试打开localhost时:8080 / contacts我有404错误......

如果我从我的IDE(intellij)启动该应用程序,它运行正常,如果任何人能够解释我错过的内容,我将非常高兴。

1 个答案:

答案 0 :(得分:3)

catalina.out日志清楚地显示您的@Controller已映射到路径/contacts

INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/contacts],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.apress.prospring3.ch17.web.controller.ContactController.list(org.springframework.ui.Model)

但是,您尝试使用路径

访问此处理程序
localhost:8080/contacts 

只有当您将webapp配置为具有/的上下文路径并且我很确定它不是。

时,这才有效。

尝试使用

localhost:8080/[myapp]/contacts

其中[myapp]webapps文件夹中应用程序文件夹的名称。

有关如何更改该路径的信息,请参阅this answer