public class TransactionalApplicationListenerMethodAdapter extends ApplicationListenerMethodAdapter implements TransactionalApplicationListener<ApplicationEvent>
GenericApplicationListener
adapter that delegates the processing of
an event to a TransactionalEventListener
annotated method. Supports
the exact same features as any regular EventListener
annotated method
but is aware of the transactional context of the event publisher.
Processing of TransactionalEventListener
is enabled automatically
when Spring's transaction management is enabled. For other cases, registering
a bean of type TransactionalEventListenerFactory
is required.
TransactionalEventListener
,
TransactionalApplicationListener
,
TransactionalApplicationListenerAdapter
TransactionalApplicationListener.SynchronizationCallback
logger
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
TransactionalApplicationListenerMethodAdapter(String beanName,
Class<?> targetClass,
Method method)
Construct a new TransactionalApplicationListenerMethodAdapter.
|
Modifier and Type | Method and Description |
---|---|
void |
addCallback(TransactionalApplicationListener.SynchronizationCallback callback)
Add a callback to be invoked on processing within transaction synchronization,
i.e.
|
protected String |
getDefaultListenerId()
Determine the default id for the target listener, to be applied in case of
no
annotation-specified id value . |
String |
getListenerId()
Return an identifier for the listener to be able to refer to it individually.
|
TransactionPhase |
getTransactionPhase()
Return the
TransactionPhase in which the listener will be invoked. |
void |
onApplicationEvent(ApplicationEvent event)
Handle an application event.
|
doInvoke, getCondition, getDetailedErrorMessage, getOrder, getTargetBean, getTargetMethod, handleAsyncError, handleResult, processEvent, resolveArguments, supportsEventType, supportsSourceType, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forPayload, forPayload, getOrder, processEvent
public TransactionalApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, Method method)
beanName
- the name of the bean to invoke the listener method ontargetClass
- the target class that the method is declared onmethod
- the listener method to invokepublic TransactionPhase getTransactionPhase()
TransactionalApplicationListener
TransactionPhase
in which the listener will be invoked.
The default phase is TransactionPhase.AFTER_COMMIT
.
getTransactionPhase
in interface TransactionalApplicationListener<ApplicationEvent>
public String getListenerId()
TransactionalApplicationListener
It might be necessary for specific completion callback implementations to provide a specific id, whereas for other scenarios an empty String (as the common default value) is acceptable as well.
protected String getDefaultListenerId()
annotation-specified id value
.
The default implementation builds a method name with parameter types.
getListenerId()
public void addCallback(TransactionalApplicationListener.SynchronizationCallback callback)
TransactionalApplicationListener
TransactionalApplicationListener.processEvent(E)
is being triggered during actual transactions.addCallback
in interface TransactionalApplicationListener<ApplicationEvent>
callback
- the synchronization callback to applypublic void onApplicationEvent(ApplicationEvent event)
ApplicationListener
onApplicationEvent
in interface ApplicationListener<ApplicationEvent>
onApplicationEvent
in class ApplicationListenerMethodAdapter
event
- the event to respond to