【问题标题】:Spring mvc application does not work as war in tomcat but it works well from IDESpring mvc 应用程序在 tomcat 中不能作为战争使用,但在 IDE 中运行良好
【发布时间】:2013-09-02 14:10:05
【问题描述】:

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

如果我从我的 IDE (intellij) 启动该应用程序,它工作正常,如果有人能解释我错过了什么,我会非常高兴。

【问题讨论】:

  • 贴出catalina.out日志文件的相关区域。
  • 这是我的输出:freetexthost.com/oq0xlzi3f5
  • 我不认为这些日志包含您何时获得 404 的痕迹。您可以上传吗?另外你用什么来建立一个WAR? Maven 如果是这样,看起来你没有在战争中包含所需的配置文件,这可能在你的 ide 中的类路径中
  • 控制台上没有任何痕迹,404 我在尝试打开应用程序 url 时进入浏览器。我正在使用 maven (mvn clean install) 然后从 /temp 文件夹中获取 war 文件并将其放入 tomcat/webapps

标签: spring spring-mvc tomcat7 apache-tiles


【解决方案1】:

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,了解如何更改该路径。

【讨论】:

  • 是的!十分感谢!就是这样!在我配置为/ 的IDE 上下文路径中,你救了我的大脑! (弓)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-25
  • 1970-01-01
  • 1970-01-01
  • 2017-01-04
  • 2020-08-21
  • 1970-01-01
相关资源
最近更新 更多