Simplest Spring MVC Hello World Example / Tutorial – Spring Model – View – Controller Tips

Do you have any one of below question?

  • Developing a Spring Framework MVC 4 application step-by-step..
  • java – Spring MVC tutorial from the scratch
  • Spring MVC Fast Tutorial
  • Spring MVC Framework Tutorial
  • First Spring MVC application tutorial
  • Spring 4 MVC Tutorials, AJAX Demo, jQuery Demo, JavaScript Demo, Tips & Tricks Spring 4 MVC

Then you are at right place. Here I’ll demonstrate simple Spring MVC framework for building web applications.

First thing first. I’m using below tools which you may need to download if you don’t have already.

  1. Tomcat 7.0.56 (Download link)
  2. Eclipse IDE Luna Service Release 1 v4.4.1(Download link)
  3. Spring 4.1.1 (No download required)
  4. JDK 1.7 (Download link)

Main goal for this tutorial to create Spring MVC Application in the simplest way. This is how our application result will look like. This is a final result once you complete all below steps.

Welcome page ==> index.jsp

CrunchifySpringMVCTutorial index.jsp page

Result returns from Controller Class :)

Message Coming from Controller

Now Let’s get started

Step 1.

Open Eclipse and Create Dynamic Web Project CrunchifySpringMVCTutorial.

Create Dynamic Web Project in Eclipse

Crunchify Spring MVC Example

Step 2.

Use Target Runtime as Apache Tomcat 7.0

Step 3.

Convert Project to Maven Project to add all required Spring MVC dependencies to project.

Steps: Right click on project -> Configure -> Convert to Maven project.

Convert CrunchifySpringMVCTutorial to Maven project

Step 4.

Add below jar dependencies to project.

Srping MCV Dependencies - Crunchify Spring Tutorial

Here is my pom.xml file.

Step 5.

Create Spring Configuration Bean file. /WEB-INF/crunchify-servlet.xml

In the above crunchify-servlet.xml  configuration file, we have defined a tag <context:component-scan> . This will allow Spring to load all the components from package com.crunchify.controller  and all its child packages.

This will load our CrunchifyHelloWorld.class . Also we have defined a bean viewResolver. This bean will resolve the view and add prefix string /WEB-INF/jsp/  and suffix .jsp to the view in ModelAndView. Note that in our CrunchifyHelloWorld class, we have return a ModelAndView object with view name welcome. This will be resolved to path /WEB-INF/jsp/welcome.jsp .

Step 6.

Map Spring MVC in /WEB-INF/web.xml file.

NOTE: if you don’t see web.xml file in your “dynamic web project” then follow these steps.

The above code in web.xml will map DispatcherServlet with url pattern /welcome.jsp. Also note that we have define index.jsp as welcome file.

One thing to note here is the name of servlet in <servlet-name> tag in web.xml. Once the DispatcherServlet is initialized, it will looks for a file name [servlet-name]-servlet.xml  in WEB-INF folder of web application. In this example, the framework will look for file called crunchify-servlet.xml.

Step 7.

Create Controller Class.

  • Package: com.crunchify.controller
  • Filename: CrunchifyHelloWorld.java

Create Spring Controller Class CrunchifyHelloWorld

Note that we have annotated the CrunchifyHelloWorld class with @Controller and @RequestMapping("/welcome"). When Spring scans our package, it will recognize this bean as being a Controller bean for processing requests. The @RequestMapping annotation tells Spring that this Controller should process all requests beginning with /welcome in the URL path. That includes /welcome/* and /welcome.html.

The helloWorld() method returns ModelAndView object. The ModelAndView object tries to resolve to a view named “welcome” and the data model is being passed back to the browser so we can access the data within the JSP. The logical view name will resolve to /WEB-INF/jsp/welcome.jsp . Logical name “welcome” which is return in ModelAndView object is mapped to path /WEB-INF/jsp/welcome.jsp.

The ModelAndView object also contains a message with key “message” and Detailed value. This is the data that we are passing to our view. Normally this will be a value object in form of java bean that will contain the data to be displayed on our view. Here we are simply passing a string.

Step 8.

The View: Create /WebContent/index.jsp and /WebContent/WEB-INF/jsp/welcome.jsp  file

After everything this is how your workspace should look like.

CrunchifySpringMVCTutorial by Crunchify - Eclipse Package Structure

Step 9.

Deploy project to Apache Tomcat and start tomcat.

Start Tomcat Server

Step 10.

Visit: http://localhost:8080/CrunchifySpringMVCTutorial/ and you are all set.

Hurrey.. Now you know Hello World Spring MVC 4 Example. Let me know if you encounter any exception while running this.  There are lot more example you can find here.

Have anything to add to this article? Please chime in and join the conversion.

Enjoyed this post?

Be sure to subscribe to the Crunchify newsletter and get regular updates about awesome posts just like this one and more! Join more than 13000 subscribers!

  • Tomj

    Hi! I found this searching for spring 4.1 skill. Good tutorial! And I hav some question!

    1.

    Now, I made the webpage using spring 3.0.5. Can I ask the most difference spring 3~ between 4.1.x?

    the most important functional thing.

    2.
    And I hav more curious about this question. Is there any difference spring 3~ between 4.1.x about coding skill(programming way, method, whatever)?

    I’m so sorry for bothering u..
    I’m already waiting for your answer!
    Good Bye!

  • Rohan

    First Tutorial I get that works. Thanks man!

    • http://crunchify.com/ App Shah

      Thanks Rohan. Appreciate your feedback.

  • Rohan

    Which specific version of eclipse should you use? I have tried the eclipse Luna IDE for Java Developers as well as the Luna SDK. Not one of those have the option of Creating a new Dynamic Web Project. Has it been renamed in Luna or am I doing something wrong?

    • http://crunchify.com/ App Shah

      Hi Rohan. I’m using Eclipse version 4.4.2.

  • bujawe

    im stuck at step 4. my dependencies window is blank. help pls

    • http://crunchify.com/ App Shah

      Hi Bujawe – would you please send/upload screenshot?

  • Snehal

    Hi App,

    I am getting below error while starting the server.

    SEVERE: Servlet [spring] in web application [/app] threw load() exception

    java.lang.ClassNotFoundException: org.springframework.context.ApplicationContextAware

    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)

    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)

    at java.lang.ClassLoader.defineClass1(Native Method)

    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)

    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2957)

    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210)

    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690)

    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)

    at java.lang.ClassLoader.defineClass1(Native Method)

    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)

    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2957)

    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210)

    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690)

    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)

    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:506)

    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:488)

    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:115)

    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1148)

    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)

    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5266)

    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5554)

    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)

    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)

    at java.util.concurrent.FutureTask.run(FutureTask.java:262)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

    at java.lang.Thread.run(Thread.java:745)

  • Pankaj

    Good Day, App!

    I am constantly getting the following error no matter what I do.

    Caused by: java.lang.ClassNotFoundException: org.springframework.web.multipart.MultipartResolver

    Please help.

    • http://crunchify.com/ App Shah

      Hi Pankaj. Would you be able to paste complete stack trace? It may help find a solution.

  • Dharmesh Prajapati

    Thank you……. vry nyc…..

  • Dago Mx

    Hi, do you know how to work with JPA2?

    • http://crunchify.com/ App Shah

      Hi Dago – great point. Will publish a new tutorial on JPA2 in couple of weeks.

      • Dago Mx

        Thanks! That would be great! I’m reading a book about JPA 2 but a tutorial would be better 😀

        Do you know if JPA is like entity framework in .NET? I’m looking for something like that.

        By the way, I like working with Netbeans!

  • Arun K

    I tried and got a 404 error using Tomcat 7 when I clicked the link. Tried on Glassfish 4 and it worked fine. Weird.

    • http://crunchify.com/ App Shah

      Hi Arun – are you still getting this error? Have you tried cleaning up project?

      • Arun K

        The error is gone now. It is working in Tomcat as well. I guess multiple deployments for tutorials from different sites (which didnt work) messed up the server or eclipse browser cache. It started working when I restarted Eclipse.

        • http://crunchify.com/ App Shah

          Awesome. Thanks for an update Arun. Glad it worked after Eclipse restart :)

      • Arun K

        Thank you very much. This is by far the only working tutorial I found except from very old ones (completely xml config)

  • Aish

    The welcome page returns 404 all the time.. Please help

    • http://crunchify.com/ App Shah

      Hi Aish – are you still getting this error? Have you tried cleaning up project?

    • CentiMan

      Make sure you have WEB-INF folder in src/main/webapp folder. I assume you wont have webapp folder, so create one . Update project and try to run it . I guess its not able to map servlet. Even I got it that way, but its a minor change that I tried and it works .

      • http://crunchify.com/ App Shah

        Thanks for an update.

  • Sergio

    Apart a tiny change to be able to do it in Weblogic (I need in web.xml web-app_2_5.xsd) … perfect tutorial!!!!

    • http://crunchify.com/ App Shah

      I’m glad it worked Sergio.

  • Tuto

    very * 100000 Thank you :)

    • http://crunchify.com/ App Shah

      Thanks for stopping by and taking a time to comment. Appreciate it.

  • georgealex

    Thanks that works and your explanation is very clear but….. I still have not had a eureka moment with Spring. There seem a lot of xml for not very much, I have to lean/know this but I’m still not seeing the point and its a lot lot mess intuitive that when I learned Jersey. I’ll plough through your other tutorial as this was the best I’ve seen so far, so thanks

    • http://crunchify.com/ App Shah

      Thanks for taking a time to post your feeling. Happy coding.

  • MVR

    You saved my ass bro…..Thanks a lot!

  • kt

    I get this 404 error from the Tomcat server 7.0.59. This is a copy-and-paste as plain text. The words ‘type’, ‘message’, ‘description’ are highlighted in the server. Thanks.

    HTTP Status 404 – /CrunchifySpringMVCTutorial/

    type Status report

    message /CrunchifySpringMVCTutorial/

    description The requested resource is not available.

    • http://crunchify.com/ App Shah

      Hi There. Can you please share complete stack trace to debug further?

  • DerBernie

    thank you! <3

  • Олег Богданович

    Hi! Thanks about your article, its the better that i`ve seen before. And i want to ask about: when I installed in Eclipse Luna from marketsplase Spring Tools Suite in Creating new project i see new folder – Spring. If creating project by that way, is it all correct there?

    • http://crunchify.com/ App Shah

      Hi there – I believe you could have any name for your project.

      • Олег Богданович

        it`s not about name question, about way of creating a new project, ’cause the creating a new project with STS is easier and faster, and maybe you work with STS and know about it…

        • http://crunchify.com/ App Shah

          Oh i see. Sorry but I never tried SpringSource Tool Suite (STS) before. Would definitely try it out. Thanks.

  • Steve Atkinson

    Great tutorial! Got 404 oon the welcome page but that was only because I forgot to put welcome.jsp inside the jsp folder.

    One small improvement you can make – currently the markup generated by helloWorldMethod is invalid – there is an unclosed div. Also, if we’re being picky, there’s a missing DOCTYPE and the align attribute is deprecated. I made teh following changes to make it pass w3c validation:

    – add to the top of both jsp files
    – added “” to the end of the message variable in HelloWorld.java
    – replaced “align =center” with style=”text-align:center;” in message value and in welcome.jsp (style attr is already there in welcome.jsp, just add text-align=”center”; to it

    • http://crunchify.com/ App Shah

      Thanks Steve. Fixed all 3 suggested changes.

  • Dante C

    hi! in this example, in the web.xml in the servlet mapping tag, the url pattern is set as /welcome.jsp and when I try to run the application, says that can’t find /welcome.html, so I had to change the url pattern with /welcome.html and then all work out fine. I don’t know if is a mistake in the example’s code but this change solves the problem I had

    • http://crunchify.com/ App Shah

      Hi Dante – Thanks for your feedback. Based on your update i’ve added below 3 url-pattern into web.xml file.

              /welcome.jsp
              /welcome.html
              *.html
  • Kalirajan

    Message not print in the welcome page… it just print the what we wrote in JSP page…

    • http://crunchify.com/ App Shah

      Hi Kalirajan – are you getting any error message in console and/or Web Browser console window?

  • Michail

    you are awesome thanks!

  • Astro

    Hey, thanks for the tutorial :) Everything what you wrote here, worked for me just fine.
    I did everything step by step and eventually I made a copy of this tutorial`s project for some playground stuff and practice, and ofc I changed the name of the new project to “beer-blog-hiccup”.
    And now, how do I change the http://localhost:8080/CrunchifySpringMVCTutorial/ directory to http://localhost:8080/beer-blog-hiccup/ ? In the attached picture, you can see that between the parenthesis there is still (CrunchifySpringMVCTutorial) which I believe is the source of my problems, but I changed every “CrunchifySpringMVCTutorial” in my project and it didn`t help. How do I change this directory/get ride of what is written between the parenthesis? Thanks in advance :)

    • Astro

      Found the solution here: stackoverflow. com/questions/2437465/java-how-to-change-context-root-of-a-dynamic-web-project-in-eclipse

      but the what is written between the parenthesis is still “CrunchifySpringMVCTutorial”. I have no idea why.

      • http://crunchify.com/ App Shah

        I’m glad it worked for you Astro :)

  • Fernando

    this web.xml works for me:

    /WEB-INF/index.jsp

    spring

    org.springframework.web.servlet.DispatcherServlet

    1

    spring
    /

    • http://crunchify.com/ App Shah

      Thanks Fernando for taking a time and posting a comment. I’m glad it worked for you.

  • Alex

    I have 404 when clicking on welcome. And I don’t have any exceptions in Tomcat. I tried to change mapping, but it did nothing. What could be wrong? Thank you.

    • http://crunchify.com/ App Shah

      Hi Alex – are you getting any error on browser? Would be great if you share.. Will debug at my end.

  • Ragen

    Nice and easy tutorial. You helped me a lot.

    I followed your steps, and run into a problem. When i clicked on the “Click here to See Welcome Message… ” link, i got the 404 error.
    On console was an exception: “java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet”.

    It seems java can’t find the spring jars, so i added manually the path to the jars:
    Right click on project, properties, deployment assembly, add, java build path entries, maven dependencies, finish, apply, ok.
    Now works perfectly. Thanks for the tutorial.

    • http://crunchify.com/ App Shah

      I’m glad it worked for you. Are you using maven project? If yes, then there should not be any issue.

  • Rohit Vishwakarma

    this is great article, really really grateful to you sharing this working example

    • http://crunchify.com/ App Shah

      Thanks Rohit for stopping by and taking a time to post a comment. Really appreciate it.

  • Karai

    Thanks for the tutorial tried in 4.1.4 version, updated POM accordingly and crunchify-servlet.xml xsd versions in beans tag. Worked like a charm !!!! Excellent tutorial for beginner

    • http://crunchify.com/ App Shah

      Thanks Karai for stopping by. Glad it worked.

  • Bhargav Patel

    Hi All, I am new in Spring,

    I am getting HTTP Status 404 error even follow the below step.

    org.springframework.web.servlet.PageNotFound noHandlerFound

    WARNING: No mapping found for HTTP request with URI [/CrunchifySpringMVCTutorial/welcome.html] in DispatcherServlet with name ‘crunchify’

    Thanks

    • http://crunchify.com/ App Shah

      Hi Bhargav –

      Can you try updating servlet-mapping to below in web.xml file?

      crunchify
      /welcome.jsp

      Replace *.html with /welcome.jsp and let me know if that works.

      • Wex

        This worked for me… thanks!
        But the question is… why isnt working with *.html

        • http://crunchify.com/ App Shah

          Hi Wex – It was typo. I’ve fixed an article with the correct mapping.

  • Bhargav Patel

    Hi ALL, I am getting 404 Error even follow all below suggestion

    error like this….
    org.springframework.web.servlet.PageNotFound noHandlerFound

    WARNING: No mapping found for HTTP request with URI [/CrunchifySpringMVCTutorial/welcome.html] in DispatcherServlet with name ‘crunchify

    Thanks .

  • Kishore Saraswathula

    I have followed the steps, but blocked adding dependencies. How to get dependencies jars of spring? Do I need to download spring java or create maven project – arche type

    • http://crunchify.com/ App Shah

      Hi Kishore – I would suggest creating maven project. Maven will add all Spring dependencies specified in pom.xml file.

  • Kishore Saraswathula

    From where we get the spring jars [ as you told don’t download]

  • huynhpa

    Thank. Good work !

  • chandu

    could you please tell me where i went wrong as i got this ERROR on my browser

    thankyou

  • Mhal007

    Everything works perfectly. As Regenbogenfisch said, it’s the only working tutorial available. Don’t even waste your time for any other tutorial, like me…

    • http://crunchify.com/ App Shah

      Thanks for kind word Mhal007.

  • sachin

    Unable to run Spring project even followed given steps

    Exception i s:

    EVERE: Servlet /CrunchifySpringMVCTutorial threw load() exception

    java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet

    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)

    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)

    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532)

    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514)

    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:133)

    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1136)

    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080)

    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5027)

    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314)

    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)

    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)

    at java.util.concurrent.FutureTask.run(Unknown Source)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

    at java.lang.Thread.run(Unknown Source)

    • http://crunchify.com/ App Shah

      Hi Sachin – looks like a dependency loading issue. Can you check all of your dependencies loaded successful? You could check if spring bean loaded successful or not? http://crunfy.me/14Kez17

  • fansongy

    Really helpful. It helps me make spring work at last after all daytime trying.

  • Edmond

    I have got the “HTTP STATUS 404 – ” error after clicking “Click here to See Welcome Message… ”
    how can i solve it?

    thank you very much

    • Giovanni Michielin

      Same issue to me.
      After clicking “Click here to See……..” url is “http://localhost:8080/welcome.html” and I get HTTP 404.
      typing manually http://localhost:8080/CrunchifyMVCTutorial/welcome.html” then it works.
      So, it’s missing “/CrunchifyMVCTutorial/ ….

      Thanks

      Giovanni

      • manna

        it’s supposed to be welcome.jsp not welcome.html…I think! Although the url-pattern is for .html and .jsp

        • http://crunchify.com/ App Shah

          Yeah Manna. We could have more URL pattern under web.xml file

    • Tarken Rido

      Modify to crunchify-servlet.xml file:
      change property “prefix” value from /WEB-INF/jsp/ tp /jsp/

    • Gordon Gridley

      I had this same problem. It was because my CrunchifyHelloWorld.java was missing the “@Controller” annotation in the code above the “public class CrunchifyHelloWorld {” line

  • Frederik

    Very nice and complete beginner tutorial. Great work, man! May The Force be with you.

  • Kiên Đào Xuân

    why after I click this link “Click here to See Welcome Message… ” in file index.jsp then the project is error 404

    • http://crunchify.com/ App Shah

      Can you post errors here from your Eclipse console?

      • Daqpan

        Thanks for the tutorial. But you’ve got a problem that will result in a 404 if you click the welcome link.

        You say to create WebContent/jsp/welcome.jsp but later your screenshot shows that what you actually have is WebContent/WEB-INF/jsp/welcome.jsp in fact your crunchify-servlet.xml expects the latter.

        • http://crunchify.com/ App Shah

          Thanks Daqpan. Good catch. I’ve fixed typo and updated above tutorial.

  • krushnat

    I have created a spring mvc application. I have used external CSS but apache is saying that noPageFound for this XYZ.css

    • http://crunchify.com/ App Shah

      Hi Krushnat – this seems like CSS loading issue at client side. You don’t have to include it in at server side.

      • krushnat

        Thanks App Shah for replying.
        but whats next then?

        • http://crunchify.com/ App Shah

          Make sure your CSS file load at client side in .html or .jsp page. You could load it in head section.

  • Lakshmi

    It worked when I changed the Web.xml to the following:

    /welcome.html

  • Roberto Testa

    HTTP Status 404 – /CruncifySpringMVC/welcome.html
    why??

    • http://crunchify.com/ App Shah

      Hi Roberto – try following above steps again. I’ve completely rewrote above tutorial with maven dependencies. Fixed couple of bugs too.

  • http://crunchify.com/ App Shah

    Also, could you please try updating your web.xml file with above file content? I’ve just modified it. Hope that works.

  • http://crunchify.com/ App Shah

    404 error is mostly related to path. Make sure you have welcome.jsp page under jsp folder.

    • Himanshu Srivastava

      Thanks. It worked after changing in web.xml

  • Shadab Quddus

    Hi App Shah,don’t know why,but I am also getting 404 error.

    It is working when I did

    crunchify

    /welcome.jsp

    Which I think my controller is not working

    • http://crunchify.com/ App Shah

      Thanks Shadab. Looking at this now. Will update web.xml file above in tutorial once checked. Thanks for tips. Keep visiting.

  • calypso

    hi nice tutorial but i am getting
    “HTTP Status 404 – Servlet crunchify is not available” error why?

    • http://crunchify.com/ App Shah

      Hi calypso – as mentioned below make sure you create resource folder rather than standard new folder.

  • Sam

    HTTP Status 404 – Servlet CrunchifyHelloWorld is not available

    • http://crunchify.com/ Crunchify

      Please make sure – the resource folder needs to be created as a new “source folder” rather than just a new folder, otherwise you will get the above errors.

      • calypso

        what do u mean with “source folder” and for which folder i must do it?

        • http://crunchify.com/ App Shah

          Defining a folder full of source code to be a Source Folder is something
          that can happen in Build Path.

          -In the Package Explorer, select the project where you want the new source folder to reside.
          – From the project’s pop-up menu, select New > Source Folder. The New Source Folder wizard opens.
          – In the Project Name field, the name of the selected project appears. If you need to edit this field, you can either type a path or click Browse to choose a project that uses source folders.
          – In the Folder Name field, type a name for the new source folder.
          – If the new folder nests with an existing source folder you can check Update exclusion filters in other source folders to solve nesting. Otherwise you have to use the Java build path page (Project > Properties > Java Build Path) to fix the nesting conflict by removing other source folders.
          – Click Finish when you are done.

    • http://crunchify.com/ App Shah

      Sam – I’ve completely rewrote above project as Maven Project. Created pom.xml file and removed all manual added dependencies.. Try following all NEW steps and you shouldn’t see any issue now..

  • rehan

    Hi Sir thanx for giving awesome tutorial. i just want to ask that how can i compile this web app into .EXE file and install on another pc and run without eclipse on other computer please replay me thanks in advance.

    • http://crunchify.com/ App Shah

      Hi Rehan –
      Just export project as executable .jar and you should be all good. Just run your executable jar project with

      java -jar projectName.jar

  • http://codersnook.com/ David McMonigle

    App Shah, do you have a tutorial for setting up Spring? I tried following the new Spring setup but it’s using Maven and I might not have that setup properly. Any starter tutorials?

    • http://crunchify.com/ App Shah

      Hey David –
      I’m in process of writing Spring MVC tutorial – just fundamentals on Spring MVC. Will be out within a week.

  • Max

    Hello,

    I get 404 on welcome page.

    With this warning : WARNING: No mapping found for HTTP request with URI [/CrunchifySpringMVC3.2.1/welcome.html] in DispatcherServlet with name ‘crunchify’

    • http://crunchify.com/ App Shah

      Hi Max –
      Could you bundle your eclipse project and send me? Would like to debug it at my end.

      • Joe

        Im getting this error when I run the app 404.

        Description Resource Path Location Type
        The servlet mapping “crunchify” refers to a servlet that is not defined web.xml /CrunchifySpringMVC3.2.1/WebContent/WEB-INF Unknown Web Problem

        • http://crunchify.com/ App Shah

          Hi Joe –
          Could you please try cleaning project? Please let me know if it doesn’t work.

          • Luke

            Hi App Shah, I have the same error is there a solution for it?

          • Luke

            I have gotten it to work on my tower I wonder why the laptop spits out the Warning. Btw. Thx for your wonderful tutorials, it’s really easy to keep up and they’re always Up to date; I love it. Thx a lot and keep up the great work.

          • http://crunchify.com/ App Shah

            Thanks for an update Luke..

  • Regenbogenfisch

    Thats the ONLY working example I have seen so far. ALL the others are either faulty or incomplete or both.

    • http://crunchify.com/ App Shah

      Thanks Regenbogenfisch

    • Cassie Moy

      same. a relief for this rails dev. many thanks!

    • papinjo

      first working example, and I have been looking at them for a while (minimum at a dozen).
      Thank you so much!

    • http://crunchify.com/ App Shah

      Thanks much for taking a time and posting a comment :)

  • memento

    Hi, Thank you for this tutorial !

    I followed it step by step but I realized I didn’t have the following jars :
    – commons-logging-1.1.1.jar
    – jstl-1.2.jar

    Where did you get them ?

    Did you have to add them manually or not ?

    If not, it would mean that I didn’t install something properly.

    I have Ubuntu 13.04 with :

    – Eclipse IDE for Java EE Developers 4.3.1 (more recent than yours)
    – Apache Tomcat 7.0.50
    – Spring 3.2.1
    – The last OpenJDK (OpenJDK Runtime Environment (IcedTea 2.4.4) (7u51-2.4.4) to be precise)

    Thanks in advance.
    Greetings from France.

    • memento

      Shall I install any plugin in eclipse ?

      • http://crunchify.com/ App Shah

        Hi Memento –

        You could download those from here:
        1. Common-Logging: http://commons.apache.org/proper/commons-logging/download_logging.cgi

        2. jstl: http://download.java.net/maven/1/jstl/jars/

        • Dont_be_paranoid

          I would really really recommend Maven. Please use Maven, it simplifies things so much. Just type in the name of the artifact such as jstl and bang, there you have it from central repository. Infact you can also ask maven to download sources and JavaDoc for you.

          • http://crunchify.com/ App Shah

            Agree with you. Will update post in an hour with maven dependancy.

            
            
            	org.springframework
            	spring-aop
            	4.0.6.RELEASE
            	
            		
            			commons-logging
            			commons-logging
            		
            	
            
            
            
            
            	org.springframework
            	spring-webmvc
            	4.0.6.RELEASE
            
            
            	org.springframework
            	spring-web
            	4.0.6.RELEASE
            
            
  • Stealth Way

    WOW FINALLY a working tutorial file. Thank you so much.
    I have been searching the last 10 hours for a working MVC Hello World Example,

    I always got a 404 error page.

    Now it’s indeed working.
    I hope I can now find my mistake. Keep up this great work

    • http://crunchify.com/ App Shah

      Thank you.

  • ARM

    Hi,

    I have configure Java 7, Tomcat 7 and Eclipse Juno I am using for development.

    I have below error, please let m e know you have idea.

    java.util.concurrent.ExecutionException:
     org.apache.catalina.LifecycleException: Failed to start component 
    [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SpringMVC3.1]]
        at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
        at java.util.concurrent.FutureTask.get(FutureTask.java:111)
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:722)
    Caused
     by: org.apache.catalina.LifecycleException: Failed to start component 
    [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SpringMVC3.1]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
        ... 7 more
    Caused by: java.lang.NullPointerException
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:142)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5423)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 7 more
    
    • http://crunchify.com/ App Shah

      Hi ARM,

      Can you check this out? http://crunchify.com/org-apache-catalina-lifecycleexception/

      Hope it helps. I also faced this before..

      • ARM

        Hi App,

        Thanks for the response.

        I solve the issue, it was because of the old jar versions of Spring. It was 3.1XXX has an issue with this:

        Caused by: java.lang.NullPointerException
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java

        I replaced the jars with 3.2XXX and it works.
        Once again thanks for the response. Keep posting.

        ARM

        • http://crunchify.com/ App Shah

          Awesome. Thanks for update ARM.

    • zemo

      i have the same error have u solved it?

  • Kevin

    Hi,

    Do you know how to do the same with Apache Velocity as the viewResolver?

    • http://crunchify.com/ App Shah

      Hi Kevin,
      I haven’t tried it on Apache Velocity before but I guess this is the best time to play with it.. Will keep you posted.

  • amine

    very interesting tutoriel

    • http://crunchify.com/ App Shah

      Awesome. Glad you like it..

    • http://crunchify.com/ App Shah

      Thanks Amine..

  • http://countrysidelife.co.uk Mark

    Hi,

    Thank you ever so much for taking us into the latest wonderful Spring 3.2 via your hands on tutorial.

    Just one question: why didn’t you upgrade your web.xml from v2.5 to v3.0 which would make the whole tutorial more consistent on Spring version, right?

    Really appreciate your hard work!

    With best wishes,

    Mark

    • http://crunchify.comm App Shah

      Thanks Mark for suggestion. Good point. Haven’t noticed that as my Eclipse has generated that code for me automatically. Below lines need to be updated in web.xml as per your suggestion.

      xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      id="WebApp_ID" version="3.0">
      
  • yo

    hi,
    thanks for the nice, detailed tutorial. I got my project running but on welcome page it gives 404 error. I message i get the html with tags like following.

    type Status report

    message /iYogesh/WEB-INF/jspHello.jsp

    description The requested resource is not available.

    Apache Tomcat/7.0.30

    • http://crunchify.com App Shah

      Hi Yogesh,
      This shows jspHello.jsp file missing. Have you checked Eclipse Console to get any kind of Tomcat Startup Error?

    • M++

      the welcome.jsb should be in WebContent/WEB-INF/jsp/ but not WebContent/jsp/

      • http://crunchify.com/ App Shah

        Thanks M++ for your suggestion. Keep visiting and happy coding.