DEV Community

Cover image for 🚀 Building Spring by Example V2: Completing Module 06 - Capstone Application
Mujuzi Moses 
Mujuzi Moses 

Posted on

🚀 Building Spring by Example V2: Completing Module 06 - Capstone Application

When I started learning Spring, I noticed something about many of the tutorials I found.

They often showed how to use a feature, but not always why it worked or when you should choose one approach over another.

I learn best by building things and documenting what I discover, so I started a project called spring-by-example.

The idea is simple: instead of building one large application, I'm creating a collection of small, focused examples where each example explores a specific Spring concept with clear explanations, tests, and documentation.

I'm happy to say that I've now completed Module 06 - Capstone Application. 🎉

This module is a little different from the previous ones. Rather than focusing on individual Spring features, it brings together concepts explored throughout the project and demonstrates how they work together in complete applications.

The module covers:

  • Application Design and Architecture
  • Spring Boot
  • Spring Data and Persistence
  • REST APIs
  • Spring Security
  • Transaction Management
  • Modular Architecture with Spring Modulith
  • Application Testing
  • Integration Between Spring Technologies
  • End-to-End Application Verification

One of the most interesting parts of this module was exploring how to structure a Spring Boot application into well-defined modules.

Using Spring Modulith, I explored how to organize an application around business capabilities, establish clear module boundaries, manage dependencies, and communicate between modules using application events.

This helped reinforce an important architectural idea: even when building a monolithic application, you don't have to organize everything into one large, tightly coupled codebase.

I also explored how to test applications built with these technologies.

Testing individual components is important, but it is equally important to understand how those components behave when working together inside a running Spring application.

That led to the next example: integrating multiple Spring technologies.

For this example, I built an Order Management application using:

  • Spring Boot
  • Spring Data JPA
  • Spring Web
  • Spring Security
  • Spring Modulith
  • Transaction Management
  • Application Events

The application is organized into four business modules:

  • Catalog - manages product information.
  • Inventory - manages product stock and reservations.
  • Ordering - handles customer orders.
  • Audit - records important application events.

One of the workflows I particularly enjoyed implementing was order placement.

When a customer places an order, the application needs to coordinate several operations:

  1. Retrieve the requested product.
  2. Reserve the required inventory.
  3. Create and persist the order.
  4. Publish an application event.
  5. Record the resulting audit entry.

These operations also need to respect transaction boundaries.

For example, if there isn't enough inventory, the order should not be persisted and the inventory reservation should be rolled back.

I also explored how to use @TransactionalEventListener with AFTER_COMMIT to process an order event after the original transaction has successfully committed.

The Audit module then records the event in a separate transaction using REQUIRES_NEW.

This was a useful way to see how Spring transactions, application events, and modular architecture can work together in a realistic business workflow.

Finally, I completed the module with End-to-End Application Verification.

This example focuses on verifying a running Spring application through its externally exposed HTTP endpoints rather than testing its internal implementation directly.

Using Java's HTTP Client, Jackson, and JUnit, I built tests that communicate with the Order Management application as an external client would.

The verification covers:

  • Retrieving publicly accessible products.
  • Authentication and authorization.
  • Customer and administrator access restrictions.
  • Placing orders and retrieving order history.
  • Verifying inventory updates.
  • Preventing customers from accessing another customer's orders.
  • Verifying audit entries after successful order placement.
  • Handling invalid quantities, insufficient inventory, and nonexistent products.

I also added a dedicated GitHub Actions workflow that starts the Order Management application, waits for it to become available, and executes the end-to-end verification tests.

An important distinction I explored here is that end-to-end tests depend on a running application. They are therefore executed separately from the regular Maven build, which allows contributors to run the standard build without having to start the dependent application.

What I particularly enjoyed about this final module was seeing how the individual concepts explored throughout Spring by Example V2 come together.

Modular architecture helps organize the application. Spring Data JPA handles persistence. Spring Security protects endpoints. Transactions maintain consistency. Application events support communication between modules. Testing and end-to-end verification help establish confidence that everything works together.

The goal isn't just to know how to use individual Spring annotations or dependencies.

The bigger goal is to understand how these technologies complement one another when building real applications.

The project is open source, and I've been building it one focused example at a time:

🔗 GitHub: https://gith.ub/dsAQrAU5

🔗 GitLab: https://gitl.ab/gfDEyGH3

With Module 06 - Capstone Application complete, another important milestone in Spring by Example V2 has been reached. 🚀

Six modules completed, with each one building on the knowledge gained from the previous modules.

There's still more to explore, but I'm enjoying the process of turning what I learn into practical, runnable examples that others can learn from too.

If you've built applications with Spring, how do you approach modular architecture, transaction management, and testing workflows that involve multiple Spring technologies?

I'd love to hear about your experiences.

java #springframework #springboot #springmodulith #springdata #springsecurity #softwareengineering #opensource #github #learninginpublic #backend

Top comments (0)