Allow Propagation.NOT_SUPPORTED with @TransactionalEventListener
Closes gh-31907
This commit is contained in:
@@ -25,7 +25,8 @@ import org.springframework.transaction.event.TransactionalEventListenerFactory;
|
||||
/**
|
||||
* Extension of {@link TransactionalEventListenerFactory},
|
||||
* detecting invalid transaction configuration for transactional event listeners:
|
||||
* {@link Transactional} only supported with {@link Propagation#REQUIRES_NEW}.
|
||||
* {@link Transactional} only supported with {@link Propagation#REQUIRES_NEW}
|
||||
* and {@link Propagation#NEVER}.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 6.1
|
||||
@@ -37,9 +38,12 @@ public class RestrictedTransactionalEventListenerFactory extends TransactionalEv
|
||||
@Override
|
||||
public ApplicationListener<?> createApplicationListener(String beanName, Class<?> type, Method method) {
|
||||
Transactional txAnn = AnnotatedElementUtils.findMergedAnnotation(method, Transactional.class);
|
||||
if (txAnn != null && txAnn.propagation() != Propagation.REQUIRES_NEW) {
|
||||
throw new IllegalStateException("@TransactionalEventListener method must not be annotated with " +
|
||||
"@Transactional unless when declared as REQUIRES_NEW: " + method);
|
||||
if (txAnn != null) {
|
||||
Propagation propagation = txAnn.propagation();
|
||||
if (propagation != Propagation.REQUIRES_NEW && propagation != Propagation.NOT_SUPPORTED) {
|
||||
throw new IllegalStateException("@TransactionalEventListener method must not be annotated with " +
|
||||
"@Transactional unless when declared as REQUIRES_NEW or NOT_SUPPORTED: " + method);
|
||||
}
|
||||
}
|
||||
return super.createApplicationListener(beanName, type, method);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user