Kontakt
stefan.bente[at]th-koeln.de
+49 2261 8196 6367
Discord Server
Prof. Bente Personal Zoom
Adresse
Steinmüllerallee 4
51643 Gummersbach
Gebäude LC4
Raum 1708 (Wegbeschreibung)
Sprechstunde nach Vereinbarung
Terminanfrage: calendly.com Wenn Sie dieses Tool nicht nutzen wollen, schicken Sie eine Mail und ich weise Ihnen einen Termin zu.

Common Pitfalls with Spring Modulith

Spring Modulith is relatively new framework. There are some pitfalls and frequent misconceptions that you might encounter when working with it - especially if you have a background in the “regular Spring Boot” way of doing things. This page is intended as a loose collection of issues to be aware of when working with Spring Modulith, and how to avoid them.

Using the Wrong Annotations

The most common pitfall when working with Spring Modulith is using the wrong annotations. Spring Modulith is built on top of Spring Boot, but has in part a different set of annotations - sometimes confusingly named the same way as their Spring Boot counterparts. If you are not extra-careful, the easy way of adding imports in an IDE like IntelliJ might lead you to import the wrong annotation.

Using @SpringBootApplication for your main class

When using Spring Modulith, you should not use the @SpringBootApplication annotation on your main class. Instead, you should use the @Modulith annotation. The @Modulith annotation is a meta-annotation that includes the @SpringBootApplication annotation, but also adds some additional configuration that is necessary for Spring Modulith to work correctly.

The wrong @Service annotation

When creating a service class in Spring Modulith, it is marked by the @Service annotation. This, however is not the @Service annotation from Spring Boot (org.springframework.stereotype.Service). Instead, you need to import org.jmolecules.ddd.annotation.Service.

Annotating tests with @SpringBootTest

When writing tests for Spring Modulith, you should not use the @SpringBootTest annotation. Instead, you should use the @ApplicationModuleTest annotation (org.springframework.modulith.test.ApplicationModuleTest).

Using @AggregateRoot annotation instead of deriving your class from AggregateRoot

This is not a pitfall, but maybe worth mentioning. When creating an aggregate root in Spring Modulith, you have two ways of doing it. You can either use the @AggregateRoot annotation, or you can derive your class from org.jmolecules.ddd.types.AggregateRoot.

Although both ways should be valid, all code examples I could find use the derivation approach, not the annotation. (Drotbohm talks about this in the interview with Eberhard Wolff.) I haven’t tried the annotation with @AggregateRoot myself.

… to be continued …

This page is a work in progress. I will add more pitfalls as students (or me) will encounter them.