简体   繁体   English

我的基于Spring的Restful Web服务在部署到独立的tomcat而不是Eclipse的Tomcat时给出404

[英]My Spring based Restful webservice gives 404 when deploy to standalone tomcat instead of Eclipse's Tomcat

I am using Spring, Jpa Hibernate to create a Restful Webservices. 我正在使用Spring,Jpa Hibernate创建一个Restful Web服务。 It worked fine with Eclipse's Setup of tomcat server. 在Eclipse的tomcat服务器安装程序中,它运行良好。 But when I tried to deploy its war file to standalone tomcat's webapp folder and restart the server, it gives 404 error. 但是,当我尝试将其war文件部署到独立的tomcat的webapp文件夹并重新启动服务器时,出现404错误。

What could be the cause? 可能是什么原因? Am I missing some steps while deploying to standalone tomcat? 部署到独立的tomcat时是否缺少一些步骤?

Edit: 编辑:

Turns out when packaging the war through mvn clean install , its not packaging my web.xml and springcontext.xml. 结果是通过mvn clean install打包战争时,没有打包我的web.xml和springcontext.xml。 When I manually copy these file to the deployed war, the project work fine. 当我手动将这些文件复制到已部署的war中时,项目工作正常。

Now the question is, do any have idea why its not packaging those file. 现在的问题是,任何人都知道为什么不打包那些文件。

By default Eclipse projects put web stuff in a folder called WebContent . 默认情况下,Eclipse项目将Web内容放入名为WebContent的文件夹中。 This is not where maven expects it, so you should convert your Eclipse project to a maven project by using Right Click on Project->Configure->Convert to Maven project. 这是不是哪里maven预计,所以您应该在转换Eclipse项目的maven通过使用鼠标右键单击项目Project->Configure->Convert to Maven项目。 This will build a pom.xml that references the WebContent directory: 这将构建一个引用WebContent目录的pom.xml:

  <plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
      <warSourceDirectory>WebContent</warSourceDirectory>
      <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
  </plugin>

Here's where I'd start with the debugging: 这是我从调试开始的地方:

  • Can you connect to the standalone Tomcat at http://localhost:8080 ? 您可以通过http:// localhost:8080连接到独立的Tomcat吗?
    • If not then you probably have a port problem 如果没有,那么您可能有端口问题
  • Is the war expanded under $catalina_home/webapps ? 战争是否在$ catalina_home / webapps下展开?
    • If not then you have a deploy problem 如果没有,那么您就有部署问题
    • If you're not letting Tomcat's Manager auto-deploy then unzip the war in-place 如果您不让Tomcat的Manager自动部署,则将战争解压缩

We do exactly what you're up to on a daily basis. 我们每天都会做您要做的事情。 We develop in Eclipse, let Tomcat auto-deploy in Dev & QA, in Prod we deploy by hand as the Manager is disabled. 我们在Eclipse中进行开发,让Tomcat在Dev&QA中进行自动部署,而在Prod中,由于Manager被禁用,我们手工部署。 Once you can get things to work in Eclipse (usually the problem) then typically it's a Tomcat config problem. 一旦可以在Eclipse中正常工作(通常是问题),那么通常就是Tomcat配置问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM