diff --git a/src/main/java/com/example/easy/retry/controller/LocalRetryController.java b/src/main/java/com/example/easy/retry/controller/LocalRetryController.java index 116bba9..8f91140 100644 --- a/src/main/java/com/example/easy/retry/controller/LocalRetryController.java +++ b/src/main/java/com/example/easy/retry/controller/LocalRetryController.java @@ -1,12 +1,10 @@ package com.example.easy.retry.controller; import com.example.easy.retry.service.LocalRetryService; +import com.example.easy.retry.vo.OrderVo; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.example.easy.retry.service.impl.LocalRetryServiceImpl; @@ -92,4 +90,16 @@ public class LocalRetryController { public void localRetryIsThrowException(@RequestParam("params") String params){ localRetryService.localRetryIsThrowException(params); } + + @PostMapping("/localRetryWithRetryMethod") + /** + * 使用自定义的异常处理类 OrderRetryMethod + */ + @ApiOperation( + value = "指定自定义的异常处理类", + notes ="🥇什么是自定义的异常处理类: https://www.easyretry.com/pages/540554/#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%99%A8" + ) + public boolean localRetryWithRetryMethod(@RequestBody OrderVo orderVo){ + return localRetryService.localRetryWithRetryMethod(orderVo); + } } diff --git a/src/main/java/com/example/easy/retry/service/LocalRetryService.java b/src/main/java/com/example/easy/retry/service/LocalRetryService.java index 62804da..d36c166 100644 --- a/src/main/java/com/example/easy/retry/service/LocalRetryService.java +++ b/src/main/java/com/example/easy/retry/service/LocalRetryService.java @@ -2,6 +2,7 @@ package com.example.easy.retry.service; import com.aizuda.easy.retry.client.core.annotation.Retryable; import com.aizuda.easy.retry.client.core.retryer.RetryType; +import com.example.easy.retry.vo.OrderVo; /** * @author: www.byteblogs.com @@ -22,5 +23,6 @@ public interface LocalRetryService { void localRetryIsThrowException(String params); + boolean localRetryWithRetryMethod(OrderVo orderVo); } diff --git a/src/main/java/com/example/easy/retry/service/impl/LocalRetryServiceImpl.java b/src/main/java/com/example/easy/retry/service/impl/LocalRetryServiceImpl.java index 0f66e66..87b88e8 100644 --- a/src/main/java/com/example/easy/retry/service/impl/LocalRetryServiceImpl.java +++ b/src/main/java/com/example/easy/retry/service/impl/LocalRetryServiceImpl.java @@ -1,7 +1,9 @@ package com.example.easy.retry.service.impl; import com.aizuda.easy.retry.client.core.retryer.RetryType; +import com.example.easy.retry.customized.OrderRetryMethod; import com.example.easy.retry.service.LocalRetryService; +import com.example.easy.retry.vo.OrderVo; import org.springframework.stereotype.Component; import com.aizuda.easy.retry.client.core.annotation.Retryable; @@ -9,7 +11,6 @@ import com.example.easy.retry.exception.ParamException; /** * easy-retry中的本地重试demo - * 测试类入口见 {@link com.example.easy.retry.local.RetryableTest} */ @Component @@ -93,4 +94,12 @@ public class LocalRetryServiceImpl implements LocalRetryService { System.out.println("local retry is throw exception 方法开始执行"); throw new ParamException("此处发生了参数异常"); } + + @Override + @Retryable(scene = "localRetryWithRetryMethod", retryStrategy = RetryType.ONLY_LOCAL, + retryMethod = OrderRetryMethod.class) + public boolean localRetryWithRetryMethod(OrderVo orderVo) { + throw new NullPointerException(); + } + }