From 1b06b8b689801c6e0862f7948d4026e62bb89293 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Tue, 18 Oct 2022 11:57:21 +0200 Subject: [PATCH] GH-6 - Documenting how to use ApplicationModuleDetectionStrategy. --- src/docs/asciidoc/10-fundamentals.adoc | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/docs/asciidoc/10-fundamentals.adoc b/src/docs/asciidoc/10-fundamentals.adoc index 18382a9d..1d23cd52 100644 --- a/src/docs/asciidoc/10-fundamentals.adoc +++ b/src/docs/asciidoc/10-fundamentals.adoc @@ -176,4 +176,32 @@ Note how we concatenate the named interface's name `spi` via the double colon `: In this setup, code in __inventory__ would be allowed to depend on `SomeSpiInterface` and other code residing in the `order.spi` interface, but not on `OrderManagement` for example. For modules without explicitly described dependencies, both the application module root package *and* the SPI one are accessible. +[[fundamentals.customizing-modules]] +=== Customizing Module Detection +If the default application module model does not work for your application, the detection of the modules can be customized by providing an implementation of `ApplicationModuleDetectionStrategy`. +That interface exposes a single method `Stream getModuleBasePackages(JavaPackage)` and will be called with the package, the Spring Boot application class resides in. +You can then inspect the packages residing within that and select the ones to be considered application module base packages based on a naming convention or the like. + +Assume you declare a custom `ApplicationModuleDetectionStrategy` implementation like this: + +[source, java] +---- +package example; + +class CustomApplicationModuleDetectionStrategy implements ApplicationModuleDetectionStrategy { + + @Override + public Stream getModuleBasePackages(JavaPackage basePackage) { + // Your module detection goes here + } +} +---- + +This class needs to be registered in `META-INF/spring.factories` as follows: + +[source, text] +---- +org.springframework.modulith.model.ApplicationModuleDetectionStrategy=\ + example.CustomApplicationModuleDetectionStrategy +----