CodeMed
CodeMed

Reputation: 9201

404 error in spring mvc app running on tomcat 7

I am getting a 404 error: The requested resource is not available in a spring mvc application that I am developing in eclipse and testing on a local instance of tomcat 7 using run as ... run on server from within eclipse. The error shows up when the application launches the root url of the app.

I have not made changes to welcome.jsp, or to the xml config files since it worked last. Since the problem is NOT with the config files, I am not distracting this posting by adding them.

Also note that there is no error log or stack trace in the eclipse console.

How can I get my app to load without throwing this 404?

NOTE: I am putting my own answer below. It turns out the solution was to right click on the server instance in the servers tab in eclipse, then do a clean, then publish, then run as...run on server again, which caused the app to load with a meaningful stack trace, which I then resolved easily. As I predicted above, this problem was with eclipse, it was not with the config files. This is a valid question. There was no need to downvote it or to vote to close it. I hope it helps others.

Upvotes: 1

Views: 5940

Answers (3)

CodeMed
CodeMed

Reputation: 9201

The problem was with corruption in Eclipse. So the solution was:

  1. click on servers tab in eclipse
  2. right click on the server instance
  3. choose clean
  4. repeat right click on server instance then choose publish
  5. do run as...run on server for the app

These 5 steps resulted in the app loading with a meaningful stack trace error, which involved redundant url mapping in _someclassname_controller.java that I was in the process of editing when I last worked in Eclipse. When I resolved that stack trace error, the app ran again.

Upvotes: 1

jenaiz
jenaiz

Reputation: 547

EDIT ( I have removed the part with the viewResolver setup)

I recommend you one of these ideas:

  • Check the setup with your tomcat within eclipse and check that your changes are published in tomcat correctly

  • Go to the properties of your project and check the "Deployment Assembly" and check that the folders that you see there are ok, somethings eclipse delete some paths here or don't link with the right "deploy path", you can add more or edit

  • And the last one :). "Play a little" with the tomcat menu. Sometimes for me it works, to clean the server, or restart or the biggest one: remove the web-app, clean, restart the tomcat to be sure that the app is not restarting (somethings the clean doesn't work perfectly) and add the app again.

I hope some of those things in order. (Without to see the setup or check some things within your eclipse is difficult to imagine more)

Upvotes: 1

Alan
Alan

Reputation: 822

Ordinarily you don't put your html or jsp files under the WEB-INF folder. Usually your directory structure looks something like this:

[application root]
 |
 |_ index.html
 |_ index.jsp
 |_ media
 |    |_ css
 |    |_ js
 |    |    |_ jquery..js
 |    |    
 |    |_ images
 |_ META-INF
 |        |_ context.xml
 |_WEB-INF
         |_ classes
         |_ lib
         |    |_ jed-1.0.jar
         |    |_ gson-2.2.4.jar
         |    |_ log4j-1.2.8.jar
         |    |_ mysql-connector-java-5.1.18.jar
         |_ properties
             |_ log4j_CONSOLE.properties
             |_ log4j_FILE.properties

You will get a 404 error because the servlet container is looking for html or jsp pages under the application root folder, not under the WEB-INF folder. In addition, your web.xml file should contain something like the following to specifically point to the home page:

<welcome-file-list>
   <welcome-file>index.jsp</welcome-file>    
</welcome-file-list>

Your web.xml doesn't have this. Hope this helps.

Upvotes: 1

Related Questions