Spring MVC Demo

The Developer’s Bookshelf is a Spring MVC 4 + Spring Data JPA + Spring Security +  jQuery UI application that allows you to keep track of your personal book collection.  It’s a quick showcase of the functionality of Spring MVC.

GitHub – The source code is available on GitHub.  Instructions for how to run the project locally are shown in the README.md document.

The home page is accessible at the following URL: http://localhost:8080/springmvc-demo. Logging in as ‘admin’ with the password set to ‘admin’ will enable you to update existing books as well as add new ones.

Application Overview

This application will allow you to create, update, and delete books from your collection. All of the books in the database will be listed on the home page.

Screenshot of the Home Page
Screenshot of the Home Page

If you click on one of the books from the Home Page, then you will be taken to the Book Details page where you can view a description of the book as well as a picture of the cover.  There is an Edit Book button as well as a Delete Book button near the bottom of the page that are displayed only if you are logged in as the admin.

Screenshot of Book Details page
Screenshot of Book Details page

From the Edit Book page, you can modify all of the information for the current Book entry.

Screenshot of Book Editing page.
Screenshot of Book Editing page

Application Layers

Database Layer

The following screenshot shows the Book object in the database layer.  Note that the Photo and Description fields are not shown.

Database layer
Database Layer

Persistence Layer

The Book object is the main domain object used in the application.  Here is a code snippet that shows its data fields.  Each of the fields is mapped to the database using JPA annotations.  Hibernate is used as the persistence provider.

Service Layer

The Spring Data JPA project simplifies the CRUD operations that take place in the service layer.  For example, all three of the methods utilized in the service layer are provided by the Spring Data JPA project in its CRUDRepository interface.

Book Controller

The Book Controller handles all of the requests that are sent to the ‘/’ URI.  There are a multitude of requests that are handled by the Book Controller, but I will just list the most basic one here.

Presentation Layer

The following code snippet is from the JSPX file that shows the list of books on the Home Page.


Additional Functionality

The following is a brief description of the other technologies included in the application.

Spring Data JPA

The repository abstraction, specifically the CRUDRepository in this project, provides a simple interface for JPA-based data access.  I didn’t have to implement any JPA code for this application since the repository abstraction already offered the functionality.

jQuery UI

The Datepicker is used for the Date of Publication field.  Also, jQuery UI was used to create some of the buttons in the application.

Spring Security

The framework for a login feature exists in the application. At the moment, there is one hard-coded user called ‘admin’ with the password set to ‘admin’. If the admin is logged in, then books can be added, edited and deleted, otherwise they can only be viewed.  When viewing a book as the admin user, the Edit Book and Delete Book buttons are made visible.

H2 Embedded Database

This project uses an H2 embedded database. You will notice that the book’s pictures are included in the embedded database. In order to move pictures from MySQL over to the H2 database a few adjustments are required. Firstly, you want to make sure your photos are dumped as hexadecimals. Secondly, you have to convert each hexadecimal value into a String for it to be compatible with H2.

Apache Tiles

Apache Tiles is a free open-source templating framework.  It integrates perfectly well with Spring MVC as well as other leading MVC frameworks.


The application is currently set up for English and French. The spring:message tag is used extensively throughout the JSPXs to provide internationalization support. The properties files are located in the src/main/webapp/WEB-INF/i18n folder.


JSR-349 Bean Validation API annotations are utilized in the domain layer.  The name of a book must not be null and must be between 5-100 in size.  The publisher of a book must also not be null.  The Bean Validation API is vendor neutral so you aren’t tied to any specific provider.