如何让我的动态代理抛出检查异常?
我需要一个接口的透明包装器,有时会抛出检查过的异常,例如IOException.没有第三方AOP或编写我自己的代理是否可能?手动修改界面的所有20种方法也不是一种选择.
我正在尝试使用@Retryable调用 REST 模板的方法。如果由于通信错误而返回错误,我想重试,否则我只想在调用时抛出异常。
当 ApiException 发生时,而不是被 @Retryable 抛出和忽略,我收到了ExhaustedRetryException一个关于没有找到足够的“可恢复的”(即@Recover方法)的抱怨。
我想我会看看是否仅仅拥有可恢复的方法可能会让它快乐并且仍然按预期执行。没那么多。它没有抛出异常,而是调用了可恢复的方法。
@Retryable(exclude = ApiException include = ConnectionException, maxAttempts = 5, backoff = @Backoff(multiplier = 2.5d, maxDelay = 1000000L, delay = 150000L))
Object call(String domainUri, ParameterizedTypeReference type, Optional<?> domain = Optional.empty(), HttpMethod httpMethod = HttpMethod.POST) throws RestClientException {
RequestEntity request = apiRequestFactory.createRequest(domainUri, domain, httpMethod)
log.info "************************** Request Entity **************************"
log.info "${request.toString()}"
ResponseEntity response
try {
response = restTemplate.exchange(request, type)
log.info "************************** Response Entity **************************"
log.info "${response.toString()}"
} …Run Code Online (Sandbox Code Playgroud)