@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,9 +18,6 @@ package org.springframework.transaction.event;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.event.ApplicationListenerMethodAdapter;
|
||||
import org.springframework.context.event.EventListener;
|
||||
@@ -35,20 +32,19 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
* an event to a {@link TransactionalEventListener} annotated method. Supports
|
||||
* the exact same features as any regular {@link EventListener} annotated method
|
||||
* but is aware of the transactional context of the event publisher.
|
||||
* <p>
|
||||
* Processing of {@link TransactionalEventListener} is enabled automatically when
|
||||
* Spring's transaction management is enabled. For other cases, registering a
|
||||
* bean of type {@link TransactionalEventListenerFactory} is required.
|
||||
*
|
||||
* <p>Processing of {@link TransactionalEventListener} is enabled automatically
|
||||
* when Spring's transaction management is enabled. For other cases, registering
|
||||
* a bean of type {@link TransactionalEventListenerFactory} is required.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Juergen Hoeller
|
||||
* @since 4.2
|
||||
* @see ApplicationListenerMethodAdapter
|
||||
* @see TransactionalEventListener
|
||||
*/
|
||||
class ApplicationListenerMethodTransactionalAdapter extends ApplicationListenerMethodAdapter {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private final TransactionalEventListener annotation;
|
||||
|
||||
|
||||
@@ -65,14 +61,15 @@ class ApplicationListenerMethodTransactionalAdapter extends ApplicationListenerM
|
||||
TransactionSynchronizationManager.registerSynchronization(transactionSynchronization);
|
||||
}
|
||||
else if (this.annotation.fallbackExecution()) {
|
||||
if (this.annotation.phase() == TransactionPhase.AFTER_ROLLBACK) {
|
||||
logger.warn("Processing '" + event + "' as a fallback execution on AFTER_ROLLBACK phase.");
|
||||
if (this.annotation.phase() == TransactionPhase.AFTER_ROLLBACK && logger.isWarnEnabled()) {
|
||||
logger.warn("Processing " + event + " as a fallback execution on AFTER_ROLLBACK phase");
|
||||
}
|
||||
processEvent(event);
|
||||
}
|
||||
else {
|
||||
// No transactional event execution at all
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("No transaction is running, skipping '" + event + "' for '" + this + "'");
|
||||
logger.debug("No transaction is active - skipping " + event);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,7 +82,7 @@ class ApplicationListenerMethodTransactionalAdapter extends ApplicationListenerM
|
||||
TransactionalEventListener annotation =
|
||||
AnnotatedElementUtils.findMergedAnnotation(method, TransactionalEventListener.class);
|
||||
if (annotation == null) {
|
||||
throw new IllegalStateException("No TransactionalEventListener annotation found on '" + method + "'");
|
||||
throw new IllegalStateException("No TransactionalEventListener annotation found on method: " + method);
|
||||
}
|
||||
return annotation;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user