DEV Community

Cover image for ๐Ÿš€ Building Spring by Example: Completing the Spring Transactions Module
Mujuzi Moses ๏ฃฟ
Mujuzi Moses ๏ฃฟ

Posted on

๐Ÿš€ Building Spring by Example: Completing the Spring Transactions Module

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 8 โ€” Transactions. ๐ŸŽ‰

The module covers:

  • @Transactional
  • Transaction Propagation
  • Isolation Levels
  • Rollback Rules
  • Programmatic Transactions
  • TransactionProxyFactoryBean

One of the most interesting parts of this module was understanding what actually happens when Spring manages a transaction.

For example, @Transactional makes it possible to declaratively define transaction boundaries without having to manually begin, commit, or roll back transactions in application code.

Transaction propagation introduced another important concept: what should happen when a transactional method calls another transactional method?

I explored propagation behaviors such as REQUIRED and REQUIRES_NEW, and how they affect whether operations participate in the same transaction or run in an independent transaction.

Isolation levels then showed another side of transaction management: how concurrent transactions interact with data and what kinds of visibility and consistency guarantees they provide.

Rollback rules were another useful area to explore. A transaction does not necessarily roll back for every exception automatically, so understanding how Spring determines whether a transaction should be rolled back is important when designing transactional services.

I also explored programmatic transactions, which provide more explicit control over transaction boundaries when declarative transaction management isn't the right fit.

Finally, I looked at TransactionProxyFactoryBean, an older Spring approach to applying transaction management through proxies. It was especially useful for understanding how Spring's transaction infrastructure evolved and how it connects to the proxy concepts explored in the previous AOP module.

The goal isnโ€™t just to collect Spring annotations and APIs. Iโ€™m trying to understand how the Spring container works, how its features fit together, and why these features exist, one concept at a time.

The project is open source, and Iโ€™m continuing to build it as I learn:

๐Ÿ”— GitHub: githu.b/sbe

๐Ÿ”— GitLab: gitla.b/sbe

Thereโ€™s still a long way to go, but completing another module feels like a good milestone. ๐Ÿš€

Next up: Spring JDBC โ€” continuing to explore how Spring works with databases and how its abstractions simplify database access.

If youโ€™ve worked with Spring before, what part of Spring's transaction management do you think developers commonly misunderstand?

java #springframework #opensource #github #gitlab #learninginpublic #backend #softwareengineering #spring #transactions

Top comments (0)