How to fix HTTP Status 404 Error while running Spring MVC project?
I have been running Spring MVC projects since last ~8 years and created numerous professional and personal project in Java and Spring MVC combination.
On Crunchify we have more than ~50 Spring MVC tutorial for you to use for free. Today while running my old Hello World Spring MVC tutorial I got below error message while starting Tomcat in Eclipse IDE.
Jul 20, 2016 2:12:20 PM org.apache.catalina.core.StandardContext loadOnStartup SEVERE: Servlet [crunchify] in web application [/CrunchifySpringMVCTutorial] threw load() exception java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1308) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1142) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:518) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:499) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1102) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1038) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4997) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5289) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)
Why this exception happened:
Most probably the necessary Spring MVC related jar files are not loaded and deployed on tomcat startup. But note: these files are in your classpath and hence you are not getting any error in Eclipse IDE during development time. Happens only during runtime.
How to fix this?
Step-1
- Right click on project
- Click on
Properties
Step-2
- Click on
Deployment Assembly
Tab in the left - Click
Add...
Step-3
Click on Java Build Path Entries
Step-4
- Click on
Maven Dependencies
- Click
Finish
button
Step-5
- Redeploy Spring MVC application to Tomcat again
- Restart Tomcat
- Try accessing URL again and you shouldn’t see any error now