使用事务性注释进行Spring重试



下面的代码是使用Spring重试事务的正确方法吗?或者我还需要处理其他的事情吗?我使用的是最新的Spring Boot版本失败的事务关闭后是否重试?

@Repository
public class MyRepository {

@Retryable( value = CustomRetryAbleException.class, maxAttempts = 2, backoff = @Backoff(delay = 30000))
@Transactional
Employee updateAndGetEmployee(String date) throw CustomRetryAbleException;

{
try{

jdbcTemplate.exceute( ....) ; //Call Stored Proc
}

catch(CustomRetryAbleException c )
{
throw  CustomRetryAbleException (" Retry this Exception " );
}
}

"就是这样。">

不要忘记把@EnableRetry注释放在你的配置类(用@Configuration注释)或应用程序类(用@SpringBootApplication注释)上。

阅读这篇文章了解更多信息。

你可以记录一些东西,并故意使它无法看到它是否在延迟后再次被记录。

最新更新