Tuesday, November 20, 2012

Spring MVC 3.2 with Spring Data Rest (Part 1)

In this tutorial, we will update an existing Spring MVC app to Spring MVC 3.2 and add RESTful endpoints using Spring Data Rest. The goal is to demonstrate how we can implement HATEOAS methodology using Spring.

Before we start, please take some time to review our existing application: Spring MVC 3.1, jqGrid, and Spring Data JPA Integration Guide. If all you need is a pure Spring Data Rest application, please visit the official Spring Data Rest starter web application.

Table of Contents

Part 1: Configuration
  • Update the pom.xml
  • Update the web.xml
  • Spring Configurations
  • Repositories
Part 2: Running the application


  • Spring core 3.2.0.RC1
  • Spring Data Rest 1.0.0.RC3
  • Spring Data JPA 1.1.0.RELEASE
  • jQuery 1.6.4
  • jqGrid 4.3.1
  • See pom.xml for details


To access the source code, please visit the project's Github repository (click here)

Update the pom.xml

Here are the changes that we need to do:
  • Update the Spring core version
  • Update the Spring Data JPA version
  • Add Spring Data Rest dependency

Note: I also added the profiles section at the end of the pom.xml, so that we can expose the repositories in a clean manner.

Update the web.xml

Here are the changes that we need to do:
  • Update the web-app version to 2.5 (optional)
  • Update the display-name (optional)
  • Add Spring Data Rest servlet

Spring Configurations

We need to do three tasks:
  • Update the database name
  • Create a spring-data-rest.xml
  • Update the applicationContext.xml

Update the database name

Open the spring.properties under WEB-INF folder, and update it as follows:

In the original application, the declared database name is spring_jqgrid_tutorial, let's update it to spring_data_rest_tutorial (though this is really not needed).

Create a spring-data-rest.xml

Update the applicationContext.xml

There's not much update here. We just need to import the spring-data-rest.xml as follows:


We need to do two tasks:
  • Update UserRepository
  • Create a new repository RoleRepository

The only update here is the addition of the annotation @Param to the UserRepository. This is required so that we can expose the parameters in the search queries.

We need to create a new repository for the Role domain so that we can expose it as RESTful endpoint:


In the next section, we will build and run the application and test our RESTful endpoints. Click here to proceed.
StumpleUpon DiggIt! Del.icio.us Blinklist Yahoo Furl Technorati Simpy Spurl Reddit Google I'm reading: Spring MVC 3.2 with Spring Data Rest (Part 1) ~ Twitter FaceBook

Subscribe by reader Subscribe by email Share


  1. This is perfect, jsut what I looking for, just one update, for spring-data-rest-webmvc version: 1.1.0.M1I had to use


    instead of


  2. Also comment out this in spring-data-rest.xml , since "RepositoryRestConfiguration" has been removed in 1.1.0.M1 version as well.

  3. Is anyone else getting "Dependency not found" for version 1.1.0.M1?

  4. Yes, me too.
    Still no idea yet, how to fix it.

  5. Added the following maven repositories in pom.xml for getting the version 1.1.0.M1:

    id: com.springsource.repository.bundles.release
    url: http://repository.springsource.com/maven/bundles/release

    id: com.springsource.repository.bundles.external
    url: http://repository.springsource.com/maven/bundles/external

    id: com.springsource.repository.libs-snapshot
    url: http://repo.springsource.org/libs-snapshot



  6. How to get the primary key value like ("ID")

  7. I have read your blog its very attractive and impressive. I like it your blog.

    Spring online training Spring online training Spring Hibernate online training Spring Hibernate online training Java online training

    spring training in chennai spring hibernate training in chennai

  8. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

    core java training in Electronic City

    Hibernate Training in electronic city

    spring training in electronic city

    java j2ee training in electronic city

  9. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea.
    here by i also want to share this.
    Java training in Chennai

    Java training in Bangalore

    Java online training

    Java training in Pune

  10. The effectiveness of IEEE Project Domains depends very much on the situation in which they are applied. In order to further improve IEEE Final Year Project Domains practices we need to explicitly describe and utilise our knowledge about software domains of software engineering Final Year Project Domains for CSE technologies. This paper suggests a modelling formalism for supporting systematic reuse of software engineering technologies during planning of software projects and improvement programmes in Project Centers in Chennai for CSE.

    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai

  11. Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place.. Wondering where to go in 2019? Things to do has ranked as the best include a remote, idyllic island, the design capital ...

  12. Effective blog with a lot of information. I just Shared you the link below for Courses .They really provide good level of training and Placement,I just Had Spring Classes in this institute , Just Check This Link You can get it more information about the Spring course.

    Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery