简体   繁体   中英

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. It worked fine with Eclipse's Setup of tomcat server. But when I tried to deploy its war file to standalone tomcat's webapp folder and restart the server, it gives 404 error.

What could be the cause? Am I missing some steps while deploying to standalone tomcat?

Edit:

Turns out when packaging the war through mvn clean install , its not packaging my web.xml and springcontext.xml. When I manually copy these file to the deployed war, the project work fine.

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 . 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. This will build a pom.xml that references the WebContent directory:

  <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 ?
    • If not then you probably have a port problem
  • Is the war expanded under $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

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. Once you can get things to work in Eclipse (usually the problem) then typically it's a Tomcat config problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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