@Target(value={METHOD,ANNOTATION_TYPE}) @Retention(value=RUNTIME) @Documented @EventListener public @interface TransactionalEventListener
EventListener that is invoked according to a TransactionPhase.
This is an an annotation-based equivalent of TransactionalApplicationListener.
If the event is not published within an active transaction, the event is discarded
unless the fallbackExecution() flag is explicitly set. If a transaction is
running, the event is processed according to its TransactionPhase.
Adding @Order to your annotated
method allows you to prioritize that listener amongst other listeners running before
or after transaction completion.
NOTE: Transactional event listeners only work with thread-bound transactions
managed by PlatformTransactionManager.
A reactive transaction managed by ReactiveTransactionManager
uses the Reactor context instead of thread-local attributes, so from the perspective of
an event listener, there is no compatible active transaction that it can participate in.
TransactionalApplicationListener,
TransactionalApplicationListenerMethodAdapter| Modifier and Type | Optional Element and Description |
|---|---|
Class<?>[] |
classes
The event classes that this listener handles.
|
String |
condition
Spring Expression Language (SpEL) attribute used for making the event
handling conditional.
|
boolean |
fallbackExecution
Whether the event should be processed if no transaction is running.
|
String |
id
An optional identifier for the listener, defaulting to the fully-qualified
signature of the declaring method (e.g.
|
TransactionPhase |
phase
Phase to bind the handling of an event to.
|
Class<?>[] |
value
Alias for
classes(). |
public abstract TransactionPhase phase
The default phase is TransactionPhase.AFTER_COMMIT.
If no transaction is in progress, the event is not processed at
all unless fallbackExecution() has been enabled explicitly.
public abstract boolean fallbackExecution
@AliasFor(annotation=EventListener.class, attribute="classes") public abstract Class<?>[] value
classes().@AliasFor(annotation=EventListener.class, attribute="classes") public abstract Class<?>[] classes
If this attribute is specified with a single value, the annotated method may optionally accept a single parameter. However, if this attribute is specified with multiple values, the annotated method must not declare any parameters.
@AliasFor(annotation=EventListener.class, attribute="condition") public abstract String condition
The default is "", meaning the event is always handled.
EventListener.condition()@AliasFor(annotation=EventListener.class, attribute="id") public abstract String id
EventListener.id(),
TransactionalApplicationListener.getListenerId()