Skip to content

Commit db1c2b8

Browse files
committed
GH-322 - Move @ApplicationModuleListener into ….modulith.events in spring-modulith-events-api.
1 parent c8b81e0 commit db1c2b8

File tree

11 files changed

+77
-24
lines changed

11 files changed

+77
-24
lines changed

spring-modulith-api/src/main/java/org/springframework/modulith/ApplicationModuleListener.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,28 @@
2828
import org.springframework.transaction.event.TransactionalEventListener;
2929

3030
/**
31-
* An {@link ApplicationModuleListener} is an {@link Async} Spring {@link TransactionalEventListener} that
32-
* runs in a transaction itself. Thus, the annotation serves as syntactic sugar for the generally recommend setup to
33-
* integrate application modules via events. The setup makes sure that an original business transaction completes
34-
* successfully and the integration asynchronously runs in a transaction itself to decouple the integration as much as
35-
* possible from the original unit of work.
31+
* An {@link ApplicationModuleListener} is an {@link Async} Spring {@link TransactionalEventListener} that runs in a
32+
* transaction itself. Thus, the annotation serves as syntactic sugar for the generally recommend setup to integrate
33+
* application modules via events. The setup makes sure that an original business transaction completes successfully and
34+
* the integration asynchronously runs in a transaction itself to decouple the integration as much as possible from the
35+
* original unit of work.
3636
* <p>
3737
* It is advisable that you use these integration listeners in combination with the Spring Modulith Event Publication
3838
* Registry to make sure that the event publication does not get lost in case of an application or listener failure.
3939
*
4040
* @author Oliver Drotbohm
41-
* @see <a href="https://docs.spring.io/spring-modulith/docs/current/reference/html/#events.publication-registry">Spring
42-
* Modulith Event Publication Registry - Reference Documentation</a>
41+
* @deprecated since, 1.1. Prefer {@code org.springframework.modulith.events.ApplicationModuleListener} in
42+
* {@code spring-modulith-events-api}.
43+
* @see <a href="https://docs.spring.io/spring-modulith/reference/events.html#publication-registry">Spring Modulith
44+
* Event Publication Registry - Reference Documentation</a>
4345
*/
4446
@Async
4547
@Transactional(propagation = Propagation.REQUIRES_NEW)
4648
@TransactionalEventListener
4749
@Documented
4850
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
4951
@Retention(RetentionPolicy.RUNTIME)
52+
@Deprecated(since = "1.1", forRemoval = true)
5053
public @interface ApplicationModuleListener {
5154

5255
/**

spring-modulith-events/spring-modulith-events-amqp/src/test/java/org/springframework/modulith/events/amqp/RabbitEventPublicationIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
3232
import org.springframework.context.ApplicationEventPublisher;
3333
import org.springframework.context.annotation.Bean;
34-
import org.springframework.modulith.ApplicationModuleListener;
34+
import org.springframework.modulith.events.ApplicationModuleListener;
3535
import org.springframework.modulith.events.Externalized;
3636
import org.springframework.transaction.annotation.Transactional;
3737
import org.testcontainers.containers.RabbitMQContainer;

spring-modulith-events/spring-modulith-events-api/pom.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818
<dependencies>
1919

2020
<dependency>
21-
<groupId>org.springframework.modulith</groupId>
22-
<artifactId>spring-modulith-api</artifactId>
23-
<version>${project.version}</version>
21+
<groupId>org.springframework</groupId>
22+
<artifactId>spring-context</artifactId>
2423
</dependency>
2524

2625
<dependency>
2726
<groupId>org.springframework</groupId>
28-
<artifactId>spring-context</artifactId>
27+
<artifactId>spring-tx</artifactId>
2928
</dependency>
3029

3130
<dependency>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2022-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.modulith.events;
17+
18+
import java.lang.annotation.Documented;
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
import org.springframework.core.annotation.AliasFor;
25+
import org.springframework.scheduling.annotation.Async;
26+
import org.springframework.transaction.annotation.Propagation;
27+
import org.springframework.transaction.annotation.Transactional;
28+
import org.springframework.transaction.event.TransactionalEventListener;
29+
30+
/**
31+
* An {@link ApplicationModuleListener} is an {@link Async} Spring {@link TransactionalEventListener} that runs in a
32+
* transaction itself. Thus, the annotation serves as syntactic sugar for the generally recommend setup to integrate
33+
* application modules via events. The setup makes sure that an original business transaction completes successfully and
34+
* the integration asynchronously runs in a transaction itself to decouple the integration as much as possible from the
35+
* original unit of work.
36+
* <p>
37+
* It is advisable that you use these integration listeners in combination with the Spring Modulith Event Publication
38+
* Registry to make sure that the event publication does not get lost in case of an application or listener failure.
39+
*
40+
* @author Oliver Drotbohm
41+
* @see <a href="https://docs.spring.io/spring-modulith/reference/events.html#publication-registry">Spring Modulith
42+
* Event Publication Registry - Reference Documentation</a>
43+
*/
44+
@Async
45+
@Transactional(propagation = Propagation.REQUIRES_NEW)
46+
@TransactionalEventListener
47+
@Documented
48+
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
49+
@Retention(RetentionPolicy.RUNTIME)
50+
public @interface ApplicationModuleListener {
51+
52+
/**
53+
* Whether the transaction to be run for the event listener is supposed to be read-only (default {@literal false}).
54+
*/
55+
@AliasFor(annotation = Transactional.class, attribute = "readOnly")
56+
boolean readOnlyTransaction() default false;
57+
}

spring-modulith-events/spring-modulith-events-core/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@
1818

1919
<dependencies>
2020

21-
<dependency>
22-
<groupId>org.springframework.modulith</groupId>
23-
<artifactId>spring-modulith-api</artifactId>
24-
<version>${project.version}</version>
25-
</dependency>
26-
2721
<dependency>
2822
<groupId>org.springframework.modulith</groupId>
2923
<artifactId>spring-modulith-events-api</artifactId>

spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/support/DelegatingEventExternalizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import java.util.function.BiConsumer;
1919

20-
import org.springframework.modulith.ApplicationModuleListener;
20+
import org.springframework.modulith.events.ApplicationModuleListener;
2121
import org.springframework.modulith.events.EventExternalizationConfiguration;
2222
import org.springframework.modulith.events.RoutingTarget;
2323
import org.springframework.stereotype.Component;

spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/support/EventExternalizationSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import org.slf4j.Logger;
1919
import org.slf4j.LoggerFactory;
20-
import org.springframework.modulith.ApplicationModuleListener;
20+
import org.springframework.modulith.events.ApplicationModuleListener;
2121
import org.springframework.modulith.events.EventExternalizationConfiguration;
2222
import org.springframework.modulith.events.RoutingTarget;
2323
import org.springframework.modulith.events.core.ConditionalEventListener;

spring-modulith-events/spring-modulith-events-jms/src/test/java/org/springframework/modulith/events/jms/JmsEventPublicationIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.springframework.boot.test.context.SpringBootTest;
2727
import org.springframework.context.ApplicationEventPublisher;
2828
import org.springframework.context.annotation.Bean;
29-
import org.springframework.modulith.ApplicationModuleListener;
29+
import org.springframework.modulith.events.ApplicationModuleListener;
3030
import org.springframework.modulith.events.Externalized;
3131
import org.springframework.transaction.annotation.Transactional;
3232

spring-modulith-examples/spring-modulith-example-epr-jdbc/src/main/java/example/inventory/InventoryManagement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
2323
import org.springframework.context.ApplicationEventPublisher;
24-
import org.springframework.modulith.ApplicationModuleListener;
24+
import org.springframework.modulith.events.ApplicationModuleListener;
2525
import org.springframework.stereotype.Service;
2626

2727
/**

spring-modulith-examples/spring-modulith-example-epr-mongodb/src/main/java/example/inventory/InventoryManagement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
2323
import org.springframework.context.ApplicationEventPublisher;
24-
import org.springframework.modulith.ApplicationModuleListener;
24+
import org.springframework.modulith.events.ApplicationModuleListener;
2525
import org.springframework.stereotype.Service;
2626

2727
/**

0 commit comments

Comments
 (0)