Spring MVC Restful Service

Spring 3 MVC supports RESTful web services in its MVC layer.

In this tutorial, we will use Spring MVC annotations to build RESTful web application.


1. Technologies used

  • Spring 3.2.8.RELEASE
  • Maven 3.0.5
  • Eclipse 4.2
  • JDK 1.6
  • Tomcat 6.0


2. Project structure

We create a new web application project with Maven


3. Project dependencies

We add the Spring dependencies in the pom.xml


4. Spring MVC Controller

It will be published as a web service that echoes a message in a JSP page.


5. JSP Views

It will be used to display the value returned by RestController

File : welcome.jsp


6. Spring MVC Configuration

We add the Spring MVC configuration information and activate Spring’s auto-scan mode.

File : mvc-dispatcher-servlet.xml


7. Web app Configuration

We have to configure Spring MVC’s DispatcherServlet as the Front Controller.

File : web.xml


8. Run It

Url : http://localhost:8080/Spring-MVC-Restful-Service/Hello/Walid

Walid is the the message we want to display.



Download source code