added advanced Spring Retry example and removed Spring Retry xml config

This commit is contained in:
michaelisvy
2020-09-14 08:16:56 +08:00
parent 1b8f5ea9ee
commit da147bb6a9
6 changed files with 40 additions and 54 deletions

View File

@@ -2,18 +2,27 @@ package com.baeldung.springretry;
import java.sql.SQLException;
import org.springframework.context.annotation.PropertySource;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
public interface MyService {
@Retryable
void retryService();
@Retryable(value = { SQLException.class }, maxAttempts = 2, backoff = @Backoff(delay = 5000))
@Retryable(value = SQLException.class)
void retryServiceWithRecovery(String sql) throws SQLException;
@Retryable(value = { SQLException.class }, maxAttempts = 2, backoff = @Backoff(delay = 100))
void retryServiceWithCustomization(String sql) throws SQLException;
@Retryable( value = SQLException.class, maxAttemptsExpression = "${retry.maxAttempts}",
backoff = @Backoff(delayExpression = "${retry.maxDelay}"))
void retryServiceWithExternalConfiguration(String sql) throws SQLException;
@Recover
void recover(SQLException e, String sql);