Spring Retry with Transactional

前端 未结 4 1599
余生分开走
余生分开走 2021-01-01 13:57

Is Spring Retry guaranteed to work with Spring\'s @Transactional annotation?

Specifically, I\'m trying to use @Retryable for optimistic loc

4条回答
  •  星月不相逢
    2021-01-01 14:46

    Found the answer here: https://docs.spring.io/spring/docs/5.0.6.BUILD-SNAPSHOT/spring-framework-reference/data-access.html#transaction-declarative-annotations Table 2 indicates that the advice for the Transactional annotation has an order of Ordered.LOWEST_PRECEDENCE, which means that it is safe to combine Retryable with Transactional as long as you aren't overriding the order of the advice for either of those annotations. In other words, you can safely use this form:

    @Retryable(StaleStateException.class)
    @Transactional
    public void performDatabaseActions() {
        //Database updates here that may cause an optimistic locking failure 
        //when the transaction closes
    }
    

提交回复
热议问题