ApplicationListenerMethodAdapter resolves order on construction

Issue: SPR-14642
This commit is contained in:
Juergen Hoeller
2016-08-30 20:50:02 +02:00
parent 391752abc2
commit 58fa63fdd1
2 changed files with 48 additions and 64 deletions

View File

@@ -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;
@@ -41,14 +38,13 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
* 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;
@@ -56,7 +52,7 @@ class ApplicationListenerMethodTransactionalAdapter extends ApplicationListenerM
super(beanName, targetClass, method);
this.annotation = AnnotatedElementUtils.findMergedAnnotation(method, TransactionalEventListener.class);
if (this.annotation == null) {
throw new IllegalStateException("No TransactionalEventListener annotation found on '" + method + "'");
throw new IllegalStateException("No TransactionalEventListener annotation found on method: " + method);
}
}
@@ -68,15 +64,13 @@ 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 {
if (logger.isDebugEnabled()) {
logger.debug("No transaction is running, skipping '" + event + "' for '" + this + "'");
}
else if (logger.isDebugEnabled()) {
logger.debug("No transaction is running - skipping " + event);
}
}
@@ -85,7 +79,6 @@ class ApplicationListenerMethodTransactionalAdapter extends ApplicationListenerM
}
private static class TransactionSynchronizationEventAdapter extends TransactionSynchronizationAdapter {
private final ApplicationListenerMethodAdapter listener;