Skip to content

Commit 42a9c48

Browse files
committed
GH-863 - Add convenience method for creating a default EventExternalizationConfiguration.
1 parent e3077a7 commit 42a9c48

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

spring-modulith-events/spring-modulith-events-api/src/main/java/org/springframework/modulith/events/EventExternalizationConfiguration.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.lang.annotation.Annotation;
2121
import java.util.Collection;
22+
import java.util.List;
2223
import java.util.Optional;
2324
import java.util.function.BiFunction;
2425
import java.util.function.BiPredicate;
@@ -68,6 +69,25 @@ public static Router defaults(Collection<String> packages) {
6869
.routeAll(router);
6970
}
7071

72+
/**
73+
* Creates a default {@link DefaultEventExternalizationConfiguration} with the following characteristics:
74+
* <ul>
75+
* <li>Only events that reside in any of the given packages and that are annotated with any supported
76+
* {@code Externalized} annotation will be considered.</li>
77+
* <li>Routing information is discovered from the {code Externalized} annotation and, if missing, will default to the
78+
* application-local name of the event type. In other words, an event type {@code com.acme.myapp.mymodule.MyEvent}
79+
* will result in a route {@code mymodule.MyEvent}.</li>
80+
* </ul>
81+
*
82+
* @param packages must not be {@literal null} or empty.
83+
* @return will never be {@literal null}.
84+
* @see Externalized
85+
* @since 1.3
86+
*/
87+
public static Router defaults(String... packages) {
88+
return defaults(List.of(packages));
89+
}
90+
7191
/**
7292
* Creates a new {@link Selector} to define which events to externalize.
7393
*

spring-modulith-events/spring-modulith-events-api/src/test/java/org/springframework/modulith/events/EventExternalizationConfigurationUnitTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import java.lang.annotation.Retention;
2424
import java.lang.annotation.RetentionPolicy;
25-
import java.util.List;
2625

2726
import org.junit.jupiter.api.Test;
2827

@@ -120,7 +119,7 @@ void addsFallbackTargetIfNotSpecifiedInAnnotation() {
120119
@Test // GH-248
121120
void defaultSetup() {
122121

123-
var configuration = defaults(List.of("org.springframework.modulith")).build();
122+
var configuration = defaults("org.springframework.modulith").build();
124123

125124
var target = configuration.determineTarget(new AnotherSampleEvent());
126125

0 commit comments

Comments
 (0)