File tree 2 files changed +29
-0
lines changed
spring-core/src/main/java/com/baeldung/springevents/asynchronous
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .baeldung .springevents .asynchronous ;
2
+
3
+ import org .springframework .context .event .EventListener ;
4
+ import org .springframework .stereotype .Component ;
5
+ import org .springframework .transaction .event .TransactionPhase ;
6
+ import org .springframework .transaction .event .TransactionalEventListener ;
7
+ import org .springframework .transaction .annotation .Transactional ;
8
+ import org .springframework .scheduling .annotation .Async ;
9
+ import static org .springframework .transaction .annotation .Propagation .REQUIRES_NEW ;
10
+ import com .baeldung .springevents .synchronous .CustomSpringEvent ;
11
+
12
+ @ Component
13
+ public class AnnotationDrivenEventListener {
14
+
15
+ @ EventListener
16
+ @ Async
17
+ public void handleAsyncEvent (CustomSpringEvent event ) {
18
+ System .out .println ("Handle event asynchronously: " + event .getMessage ());
19
+ }
20
+
21
+ @ Async
22
+ @ Transactional (propagation = REQUIRES_NEW )
23
+ @ TransactionalEventListener
24
+ void handleCustom (CustomSpringEvent event ) {
25
+ /* … */
26
+ }
27
+ }
Original file line number Diff line number Diff line change 6
6
import org .springframework .context .event .ApplicationEventMulticaster ;
7
7
import org .springframework .context .event .SimpleApplicationEventMulticaster ;
8
8
import org .springframework .core .task .SimpleAsyncTaskExecutor ;
9
+ import org .springframework .scheduling .annotation .EnableAsync ;
9
10
11
+ @ EnableAsync
10
12
@ Configuration
11
13
@ ComponentScan ("com.baeldung.springevents.synchronous" )
12
14
public class AsynchronousSpringEventsConfig {
You can’t perform that action at this time.
0 commit comments