Spring Boot 4 Book Tracker Challenge

Created by Glabay | Added on Jun 07, 2026
0 reviews

Overview

In this challenge, you will build a Book Tracker web application using Java 25 and Spring Boot 4.

The goal of this project is to introduce and reinforce the concepts of Spring MVC, REST APIs, Spring Data JPA, Thymeleaf, validation, and dependency injection.

Your application will allow users to maintain a personal collection of books they have read. Users should be able to create, view, update, and delete books through a web interface while also exposing a REST endpoint that returns the data as JSON.

This project is intentionally designed to demonstrate the difference between a traditional MVC Controller and a REST Controller.


Learning Objectives

By completing this project, you should gain experience with:

  • Spring Boot 4
  • Spring MVC
  • Spring Data JPA
  • H2 In-Memory Database
  • Thymeleaf Templates
  • Form Handling
  • Bean Validation
  • Dependency Injection
  • Repository Pattern
  • Service Layer Architecture
  • REST API Development
  • Model Binding
  • Error Handling with BindingResult

Functional Requirements

Book Management

Users must be able to:

  • Create a new book
  • View all books
  • Edit an existing book
  • Delete an existing book

Book Information

Each book must contain:

Field Type
id UUID
title String
author String
yearObtained Integer
timesRead Integer
personalRating Integer (1-5)

Web Interface

Create a browser-based user interface using Thymeleaf.

The application must include:

  • A page displaying all books
  • A page for creating a new book
  • A page for editing a book

Books should be displayed as cards rather than a simple table.

The list page must demonstrate:

th:each

Iterate through all books and display them.

th:if

Conditionally display information.

th:unless

Conditionally hide information.

REST API

Create a REST endpoint that returns all books as JSON.

Example endpoint:

GET /api/books

The response should be a JSON array containing all books.

This endpoint should be consumable by:

  • CURL
  • Postman
  • Web browsers

Technical Requirements

Required Dependencies

Your solution must use:

  • Spring Boot 4
  • Spring Web MVC
  • Spring Data JPA
  • Thymeleaf
  • Validation
  • H2 Database

Architecture

Use a layered architecture.

Controller
    ↓
Service
    ↓
Repository
    ↓
Database

Direct repository access from controllers is not permitted.

Controllers

Your project must contain:

MVC Controller

Responsible for:

  • Returning Thymeleaf views
  • Populating the Model
  • Handling form submissions

Service Layer

Responsible for:

  • Business logic
  • Communicating with the Repository layer

REST Controller

Responsible for:

  • Returning JSON responses
  • Exposing API endpoints

The purpose of this challenge is to understand the difference between these two controller types.

Persistence

Use:

  • Spring Data JPA
  • H2 In-Memory Database

Books should be stored in the database rather than in collections such as:

ArrayList<Book>
HashMap<UUID, Book>

Data Seeding

Populate the application with sample books using:

CommandLineRunner

Create enough data to clearly demonstrate the application features.


Validation

All user input must be validated.

Use:

@Valid

alongside appropriate validation annotations such as:

@NotBlank
@NotNull
@Min
@Max

Validation annotations should include custom error messages.

Example:

@NotBlank(message = "Title is required.")

Validation errors must be handled using:

BindingResult

When validation fails:

  • The form should be redisplayed
  • Validation messages should be shown to the user
  • Data already entered should remain populated

H2 Console

Students are encouraged to enable and use the H2 Console to inspect their database during development.

application.properties

spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

This is optional but highly recommended.


Constraints

To encourage learning of the framework, the following restrictions apply:

Do Not

  • Store books in memory collections
  • Access repositories directly from controllers
  • Return JSON from MVC controllers
  • Return Thymeleaf views from REST controllers
  • Skip validation
  • Hardcode HTML content in controllers

Must Use

  • Service layer
  • JPA entities
  • Repository interfaces
  • Thymeleaf templates
  • Model attributes
  • Validation annotations
  • BindingResult

Suggested Pages

Home Page

Displays all books as cards.

Each card should show:

  • Title
  • Author
  • Year Obtained
  • Times Read
  • Personal Rating

Include actions for:

  • Edit
  • Delete

Create Book Page

Allows users to add a new book.

Validation errors should be displayed beside the relevant fields.


Edit Book Page

Allows users to update an existing book.

Existing values should be pre-populated.


Bonus Challenges

Complete one or more of the following:

Easy

  • Search books by title
  • Filter books by rating
  • Sort books alphabetically

Medium

  • Add a REST endpoint to retrieve a single book by ID
  • Display only books above a selected rating
  • Add Bootstrap styling

Advanced

  • Implement pagination
  • Add multiple sorting options
  • Create a statistics page showing:
    • Total books
    • Average rating
    • Total times read
    • Highest rated book