You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The exclusion of types from the Application Modules model is now described in the section about the ApplicationModules type already. That general section is now located before the discussion of simple and advanced modules.
The verification section now mentions the behavior for open modules as well.
Copy file name to clipboardExpand all lines: src/docs/antora/modules/ROOT/pages/fundamentals.adoc
+97-61Lines changed: 97 additions & 61 deletions
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,14 @@
1
1
[[fundamentals]]
2
2
= Fundamentals
3
+
:toc:
4
+
:toclevels: 3
3
5
4
6
Spring Modulith supports developers implementing logical modules in Spring Boot applications.
5
7
It allows them to apply structural validation, document the module arrangement, run integration tests for individual modules, observe the modules' interaction at runtime, and generally implement module interaction in a loosely coupled way.
6
8
This section will discuss the fundamental concepts that developers need to understand before diving into the technical support.
7
9
8
10
[[modules]]
9
-
== Application modules
11
+
== Application Modules
10
12
11
13
In a Spring Boot application, an application module is a unit of functionality that consists of the following parts:
12
14
@@ -17,6 +19,100 @@ In a Spring Boot application, an application module is a unit of functionality t
17
19
Spring Moduliths provides different ways of expressing modules within Spring Boot applications, primarily differing in the level of complexity involved in the overall arrangement.
18
20
This allows developers to start simple and naturally move to more sophisticated means as and if needed.
19
21
22
+
[[modules.application-modules]]
23
+
=== The `ApplicationModules` Type
24
+
25
+
Spring Moduliths allows to inspect a codebase to derive an application module model based on the given arrangement and optional configuration.
26
+
The `spring-modulith-core` artifact contains `ApplicationModules` that can be pointed to a Spring Boot application class:
27
+
28
+
.Creating an application module model
29
+
[tabs]
30
+
======
31
+
Java::
32
+
+
33
+
[source, java, role="primary"]
34
+
----
35
+
var modules = ApplicationModules.of(Application.class);
36
+
----
37
+
Kotlin::
38
+
+
39
+
[source, kotlin, role="secondary"]
40
+
----
41
+
var modules = ApplicationModules.of(Application::class)
42
+
----
43
+
======
44
+
The `modules` will contain an in-memory representation of the application module arrangement derived from the codebase.
45
+
Which parts of that will be detected as a module depends on the Java package structure underneath the package the class pointed to resides in.
46
+
Find out more about the arrangement expected by default in xref:fundamentals.adoc#modules.simple[].
47
+
Advanced arrangements and customization options are described in xref:fundamentals.adoc#modules.advanced[] and
48
+
49
+
To get an impression of what the analyzed arrangement looks like, we can just write the individual modules contained in the overall model to the console:
50
+
51
+
.Writing the application module arrangement to the console
52
+
[tabs]
53
+
======
54
+
Java::
55
+
+
56
+
[source, java, role="primary"]
57
+
----
58
+
modules.forEach(System.out::println);
59
+
----
60
+
Kotlin::
61
+
+
62
+
[source, kotlin, role="secondary"]
63
+
----
64
+
modules.forEach(println(it))
65
+
----
66
+
======
67
+
.The console output of our application module arrangement
68
+
[source]
69
+
----
70
+
## example.inventory ##
71
+
> Logical name: inventory
72
+
> Base package: example.inventory
73
+
> Spring beans:
74
+
+ ….InventoryManagement
75
+
o ….SomeInternalComponent
76
+
77
+
## example.order ##
78
+
> Logical name: order
79
+
> Base package: example.order
80
+
> Spring beans:
81
+
+ ….OrderManagement
82
+
+ ….internal.SomeInternalComponent
83
+
----
84
+
85
+
Note how each module is listed, the contained Spring components are identified, and the respective visibility is rendered, too.
86
+
87
+
[[modules.excluding-packages]]
88
+
==== Excluding Packages
89
+
90
+
In case you would like to exclude certain Java classes or full packages from the application module inspection, you can do so with:
* `com.example.db` -- Matches all files in the given package `com.example.db`.
111
+
* `com.example.db..` -- Matches all files in the given package (`com.example.db`) and all sub-packages (`com.example.db.a` or `com.example.db.b.c`).
112
+
* `..example..` -- Matches `a.example`, `a.example.b` or `a.b.example.c.d`, but not `a.exam.b`
113
+
114
+
Full details about possible matchers can be found in the JavaDoc of ArchUnit https://github.com/TNG/ArchUnit/blob/main/archunit/src/main/java/com/tngtech/archunit/core/domain/PackageMatcher.java[`PackageMatcher`].
115
+
20
116
[[modules.simple]]
21
117
=== Simple Application Modules
22
118
@@ -145,66 +241,6 @@ class ModuleMetadata {}
145
241
In this case code within the __inventory__ module was only allowed to refer to code in the __order__ module (and code not assigned to any module in the first place).
146
242
Find out about how to monitor that in xref:verification.adoc[Verifying Application Module Structure].
147
243
148
-
[[modules.application-modules]]
149
-
=== The `ApplicationModules` Type
150
-
151
-
Spring Moduliths allows to inspect a codebase to derive an application module model based on the given arrangement and optional configuration.
152
-
The `spring-modulith-core` artifact contains `ApplicationModules` that can be pointed to a Spring Boot application class:
153
-
154
-
.Creating an application module model
155
-
[tabs]
156
-
======
157
-
Java::
158
-
+
159
-
[source, java, role="primary"]
160
-
----
161
-
var modules = ApplicationModules.of(Application.class);
162
-
----
163
-
Kotlin::
164
-
+
165
-
[source, kotlin, role="secondary"]
166
-
----
167
-
var modules = ApplicationModules.of(Application::class)
168
-
----
169
-
======
170
-
To get an impression of what the analyzed arrangement looks like, we can just write the individual modules contained in the overall model to the console:
171
-
172
-
.Writing the application module arrangement to the console
173
-
[tabs]
174
-
======
175
-
Java::
176
-
+
177
-
[source, java, role="primary"]
178
-
----
179
-
modules.forEach(System.out::println);
180
-
----
181
-
Kotlin::
182
-
+
183
-
[source, kotlin, role="secondary"]
184
-
----
185
-
modules.forEach(println(it))
186
-
----
187
-
======
188
-
.The console output of our application module arrangement
189
-
[source]
190
-
----
191
-
## example.inventory ##
192
-
> Logical name: inventory
193
-
> Base package: example.inventory
194
-
> Spring beans:
195
-
+ ….InventoryManagement
196
-
o ….SomeInternalComponent
197
-
198
-
## example.order ##
199
-
> Logical name: order
200
-
> Base package: example.order
201
-
> Spring beans:
202
-
+ ….OrderManagement
203
-
+ ….internal.SomeInternalComponent
204
-
----
205
-
206
-
Note how each module is listed, the contained Spring components are identified, and the respective visibility is rendered, too.
Copy file name to clipboardExpand all lines: src/docs/antora/modules/ROOT/pages/verification.adoc
+1-30Lines changed: 1 addition & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -24,38 +24,9 @@ The verification includes the following rules:
24
24
* _No cycles on the application module level_ -- the dependencies between modules have to form a directed acyclic graph.
25
25
* _Efferent module access via API packages only_ -- all references to types that reside in application module internal packages are rejected.
26
26
See xref:fundamentals.adoc#modules.advanced[Advanced Application Modules] for details.
27
+
Dependencies into internals of xref:fundamentals.adoc#modules.advanced.open[Open Application Modules] are allowed.
27
28
* _Explicitly allowed application module dependencies only_ (optional) -- an application module can optionally define allowed dependencies via `@ApplicationModule(allowedDependencies = …)`.
28
29
If those are configured, dependencies to other application modules are rejected.
29
30
See xref:fundamentals.adoc#modules.explicit-dependencies[Explicit Application Module Dependencies] and xref:fundamentals.adoc#modules.named-interfaces[Named Interfaces] for details.
30
31
31
32
Spring Modulith optionally integrates with the jMolecules ArchUnit library and, if present, automatically triggers its Domain-Driven Design verification rules described https://github.com/xmolecules/jmolecules-integrations/tree/main/jmolecules-archunit[here].
32
-
33
-
[[excluding-packages]]
34
-
== Excluding Packages
35
-
36
-
In case you would like to exclude certain Java classes or full packages from the application module inspection, you can do so with:
* `com.example.db` -- Matches all files in the given package `com.example.db`.
57
-
* `com.example.db..` -- Matches all files in the given package (`com.example.db`) and all sub-packages (`com.example.db.a` or `com.example.db.b.c`).
58
-
* `..example..` -- Matches `a.example`, `a.example.b` or `a.b.example.c.d`, but not `a.exam.b`
59
-
60
-
Full details about possible matchers can be found in the JavaDoc of ArchUnit https://github.com/TNG/ArchUnit/blob/main/archunit/src/main/java/com/tngtech/archunit/core/domain/PackageMatcher.java[`PackageMatcher`].
0 commit comments