Skip to content

Commit 1b06b8b

Browse files
committed
GH-6 - Documenting how to use ApplicationModuleDetectionStrategy.
1 parent a95db9b commit 1b06b8b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/docs/asciidoc/10-fundamentals.adoc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,32 @@ Note how we concatenate the named interface's name `spi` via the double colon `:
176176
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.
177177
For modules without explicitly described dependencies, both the application module root package *and* the SPI one are accessible.
178178

179+
[[fundamentals.customizing-modules]]
180+
=== Customizing Module Detection
179181

182+
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`.
183+
That interface exposes a single method `Stream<JavaPackage> getModuleBasePackages(JavaPackage)` and will be called with the package, the Spring Boot application class resides in.
184+
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.
185+
186+
Assume you declare a custom `ApplicationModuleDetectionStrategy` implementation like this:
187+
188+
[source, java]
189+
----
190+
package example;
191+
192+
class CustomApplicationModuleDetectionStrategy implements ApplicationModuleDetectionStrategy {
193+
194+
@Override
195+
public Stream<JavaPackage> getModuleBasePackages(JavaPackage basePackage) {
196+
// Your module detection goes here
197+
}
198+
}
199+
----
200+
201+
This class needs to be registered in `META-INF/spring.factories` as follows:
202+
203+
[source, text]
204+
----
205+
org.springframework.modulith.model.ApplicationModuleDetectionStrategy=\
206+
example.CustomApplicationModuleDetectionStrategy
207+
----

0 commit comments

Comments
 (0)