Introducing Spring Modulith

Modularity has long been a sought-after goal in software engineering, offering benefits like improved maintainability, scalability, and testability.

 

In this introduction, we will explore the core concepts, features, and advantages of Spring Modulith, empowering you to embrace this cutting-edge approach to build high-quality applications that support changing business requirements.

Application modules

Each direct sub-package of the main package is considered an application module package by default (you can change strategies for how modules are registered). This package is part of the public API and can be accessed by any module. All sub-packages are considered internal, and Spring Beans are only accessible inside the module itself.

Verifying application module structure

Verification can be done simply by writing a unit test to verify the following:

If jmolecules-archunit is present on the classpath, then ArchUnit Domain-Driven-Design rules will be verified. You can check them here.

Working with application events

You can use asynchronous, transactional event handling for inter-module communication to achieve loose coupling between application modules.

 

On event publication, Spring Modulith’s event registry publication persists all interested listeners into the repository and writes completed logs afterward.

 

This way, if it fails, it can be retried again. By default, all incomplete event publications are resubmitted at application startup (you can change this behavior based on your needs).

 

JDBC, JPA, and Mongodb event repositories (and spring boot starters) are available.

 

To create a listener for a particular event, annotate your Spring Bean method with @ApplicationModuleListener annotation.

 

Publishing events can be done via Spring’s ApplicationEventPublisher or Spring Data AggregateRoot abstraction.

 

In the next release (1.1.0), there is going to be support for External events via @Externalized annotation to push events to external systems. JMS, Kafka, and AMQP protocols will be supported for now.

Integration testing application modules

To ease integration testing of asynchronous, transactional event handling Spring Modulith brings Scenario abstraction, which has helpful methods to publish and receive-verify events.

 

There are also three modes to the bootstrapping testing module:

Moments: A passage of time events API

Business processes involve the execution of specific tasks, actions, or workloads scheduled for a later date (Customer birthday, Invoice payment become overdue, etc.). Consider the flow of time as simply another instance of a Domain Event when a business-relevant occurrence takes place.

  

Spring Modulith defines the following events:

Application code can listen and react to these events, and this way, “scheduling” is part of our Domain Language.

 

Another great benefit is TimeMachine, which can be used to shift time in the future and trigger all-time events. This is very useful for integration testing, for example:

Documenting application modules

It’s very easy to generate documentation from Application modules like Spring beans, aggregate roots, published events and event listeners as well as configuration properties:

We can also visualize dependencies with generated canvases:

Module initializers

Use module initializers to run some module code before the application starts. It will start modules in order of dependent module structure.

Spring Modulith Actuator and tracing

Spring Modulith provides us a new actuator endpoint, “actuator/modulith”, which provides us Module information and can create Micrometer spans to visualize spans in tracking visualization tools.

Conclusion

Spring Modulith gives us power and ease to write well-designed application modules with Domain Driven Design principles and offers benefits like improved maintainability, scalability, and testability.

In this article:
Published:
22 November 2023

Related posts

June 26th

The Cost of Choice

Most companies spend up to 40% to much on cloud, are you? Cut spend, not options. Smart standardizations win.

Cloud cost overruns and growing technical debt rarely stem from tooling alone—they are symptoms of architectural and operational choices. This session looks at how senior technical leaders can regain control by connecting cloud spend directly to business value. We’ll explore unit‑economics thinking, ownership models, and lifecycle management practices that reduce waste while preserving delivery speed. You’ll learn how to combine FinOps principles with technical‑debt controls to create a cloud environment that is financially sustainable and technically healthy.

May 28th

AI AGENTS DESERVE AI PLATFORM

Portable patterns for Azure, AWS and GCP that survive the next upgrade

AI agents are moving rapidly from experimentation into real production use cases, but architectures vary widely across cloud platforms. In this webinar, we compare practical patterns for building and running AI agents on Azure, AWS, and Google Cloud Platform. We’ll focus on what to standardize, where to embrace cloud‑native capabilities, and how to design for security, observability, and future change. The goal is not to pick a winner, but to help leaders understand how to scale agent‑based solutions without locking themselves into fragile designs.

April 23rd

Winning on Repeat: Product Engineering in the Age of AI

Cadence, quality and outcomes over output

Delivering a successful solution once is no longer enough. In the age of AI, organizations need product engineering models that enable them to win consistently across teams, releases, and markets. This session explores how leading organizations evolve from project‑centric delivery to product‑centric execution, supported by AI‑augmented engineering practices. We’ll look at cadence, quality, and accountability, and how leadership decisions shape sustainable delivery performance over time.

April 2nd

GOVERNING AI IN PRODUCTION

Designing cloud and data platforms that survive real-world pressure

Many organizations succeed in building AI proofs of concept, far fewer succeed in scaling them safely into production. This webinar focuses on what it takes to move from experimentation to reliable, governed AI platforms. We’ll discuss platform architecture choices, model governance, security, and policy patterns that enable teams to deploy AI at scale without slowing down delivery. Designed for senior technical leaders, this session provides practical guidance on turning AI initiatives into durable capabilities that deliver value beyond the first demo

March 5th

Navigating Digital Sovereignty and Strategic Cloud Choices

How Organizations Can Balance Innovation, Compliance, and Control in a Multi-Cloud World

In today’s rapidly evolving digital landscape, organisations face increasing pressure to ensure business continuity, maintain public trust, and comply with complex regulations like NIS2, DORA, and GDPR. This webinar explores the critical concepts of digital and operational sovereignty, the strategic importance of hybrid and sovereign cloud models, and the risks of vendor lock-in.