|
|
|
@ -20,6 +20,8 @@ import java.lang.reflect.Method; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.context.ApplicationListener; |
|
|
|
import org.springframework.context.ApplicationListener; |
|
|
|
import org.springframework.core.annotation.AnnotatedElementUtils; |
|
|
|
import org.springframework.core.annotation.AnnotatedElementUtils; |
|
|
|
|
|
|
|
import org.springframework.transaction.event.TransactionPhase; |
|
|
|
|
|
|
|
import org.springframework.transaction.event.TransactionalApplicationListenerMethodAdapter; |
|
|
|
import org.springframework.transaction.event.TransactionalEventListenerFactory; |
|
|
|
import org.springframework.transaction.event.TransactionalEventListenerFactory; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -37,20 +39,22 @@ public class RestrictedTransactionalEventListenerFactory extends TransactionalEv |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public ApplicationListener<?> createApplicationListener(String beanName, Class<?> type, Method method) { |
|
|
|
public ApplicationListener<?> createApplicationListener(String beanName, Class<?> type, Method method) { |
|
|
|
Transactional txAnn = AnnotatedElementUtils.findMergedAnnotation(method, Transactional.class); |
|
|
|
TransactionalApplicationListenerMethodAdapter adapter = |
|
|
|
|
|
|
|
new TransactionalApplicationListenerMethodAdapter(beanName, type, method); |
|
|
|
if (txAnn == null) { |
|
|
|
if (adapter.getTransactionPhase() != TransactionPhase.BEFORE_COMMIT) { |
|
|
|
txAnn = AnnotatedElementUtils.findMergedAnnotation(type, Transactional.class); |
|
|
|
Transactional txAnn = AnnotatedElementUtils.findMergedAnnotation(method, Transactional.class); |
|
|
|
} |
|
|
|
if (txAnn == null) { |
|
|
|
|
|
|
|
txAnn = AnnotatedElementUtils.findMergedAnnotation(type, Transactional.class); |
|
|
|
if (txAnn != null) { |
|
|
|
} |
|
|
|
Propagation propagation = txAnn.propagation(); |
|
|
|
if (txAnn != null) { |
|
|
|
if (propagation != Propagation.REQUIRES_NEW && propagation != Propagation.NOT_SUPPORTED) { |
|
|
|
Propagation propagation = txAnn.propagation(); |
|
|
|
throw new IllegalStateException("@TransactionalEventListener method must not be annotated with " + |
|
|
|
if (propagation != Propagation.REQUIRES_NEW && propagation != Propagation.NOT_SUPPORTED) { |
|
|
|
"@Transactional unless when declared as REQUIRES_NEW or NOT_SUPPORTED: " + method); |
|
|
|
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); |
|
|
|
return adapter; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|