File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
spring-core/src/main/java/com/baeldung/springevents/asynchronous Expand file tree Collapse file tree 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 66import org .springframework .context .event .ApplicationEventMulticaster ;
77import org .springframework .context .event .SimpleApplicationEventMulticaster ;
88import org .springframework .core .task .SimpleAsyncTaskExecutor ;
9+ import org .springframework .scheduling .annotation .EnableAsync ;
910
11+ @ EnableAsync
1012@ Configuration
1113@ ComponentScan ("com.baeldung.springevents.synchronous" )
1214public class AsynchronousSpringEventsConfig {
You can’t perform that action at this time.
0 commit comments