import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
import de.example.sql.deadlocks.annotation.DeadlockRetry;
*
*/
@Aspect
+@Order(99)
public class DeadlockRetryAspect implements Ordered {
private static final Logger logger = LoggerFactory.getLogger(DeadlockRetryAspect.class);
+ /**
+ * Whatever you want as long as it has a higher value than the one used by
+ * annotation-driven transaction-manager (it uses by default Ordered.LOWEST_PRECEDENCE)
+ */
private static final int ORDER = 99;
private Collection<Class<? extends Throwable>> retryableExceptionClasses;
- <!-- enables configuration of transactional behavior based on annotations -->
- <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
+ <!--
+ It enables transactional behavior based on annotations.
+ My Aspect will always be processed before the @Transactional annotation because
+ by default the @Transactional annotation has the lowest order: Ordered.LOWEST_PRECEDENCE
+ See: http://docs.spring.io/spring/docs/3.1.0.M2/spring-framework-reference/html/transaction.html#transaction-declarative-annotations
+
+ Be careful with this order because we want our aspect to have a higher precedence order than @Transactional
+ (our aspect must be called before the transactional one)
+ -->
+ <tx:annotation-driven transaction-manager="transactionManager" mode="proxy" proxy-target-class="true" />
<!--
Not required, just for fun.