środa, 20 marca 2013

'Hello World' in Spring MVC

Simple Spring MVC "Hello world" application

In this article I will show you how build simple "Hello world" application using Spring MVC. To pass easy through this tutorial you should have set up in to your environment:
  • JDK 1.6
  • maven 3.0.4
  • eclipse Juno EE version
  1. Create Java project 

Now you have to create new java EE project. Open eclipse studio and go "File->New->Maven Project". Go to 'Select an Archetype' tab. Here you can choose archetype with Group Id: org.apache.maven.archetype and Artifact Id: maven-archetype-quickstart. In the next tab you have to add some names to your new maven project. After this step you can finish creating your skeleton project and move to the next step.

  1. Like in every maven project the main part is file pom.xml where you have to add all required dependencies to your application. Your Spring MVC pom.xml file should look like this:

Maven Setup


  1. Download required maven version form: http://maven.apache.org/download.cgi
  2. Unzip downloaded file to final destination.
  3. Add system variables:
    1.  Go to: Start -> Control Panel -> System ->Advanced system settings -> Enviroment variables ->New...
    2.  Type: variable name: M2_HOME, variable value: "unziped maven destination"
    3.  Edit 'Path' variable by adding to variable value: ;%M2_HOME%\bin
  4. You have to check if maven is available on your system enviroment now. Open Comand Line and type:
    mvn -vThe result should be similar to that: