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
Dependencies
- 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
Github
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:Repositories
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:
Next
In the next section, we will build and run the application and test our RESTful endpoints. Click here to proceed.
Share the joy:
|
Subscribe by reader Subscribe by email Share