You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

切换Quarkus Rest Client后出现递归拦截器动作过多异常

解决Quarkus替换quarkus-rest-client后出现的递归拦截器异常问题

问题根源

你遇到的java.lang.IllegalStateException: Too many recursive interceptor actions异常,核心原因是quarkus-rest-client(传统同步REST客户端)不支持返回Mutiny响应式类型(Uni/Multi)。

之前使用的quarkus-rest-reactive-client是专为响应式场景设计的,天然兼容Uni/Multi作为返回值;而替换后的quarkus-rest-client基于JAX-RS同步客户端体系,它的拦截器在处理响应式类型时会陷入循环递归,最终触发该异常。

可行解决方案

方案1:改用quarkus-rest-client-reactive(推荐)

若要保留响应式编程风格,应替换为quarkus-rest-client-reactive依赖——这是Quarkus 3.x版本中quarkus-rest-reactive-client的更名替代组件,完全兼容原有响应式代码,无需修改接口和业务逻辑。

方案2:调整为同步客户端风格

若必须使用quarkus-rest-client,需将Rest Client接口改为同步返回类型:

// 修改后的Rest Client接口
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import java.util.List;

@Path("/v1/db/comments")
@RegisterRestClient(configKey = "comment-reactive-client")
public interface CommentRestClient {
    @GET
    List<Comment> getComments();
}

同时修改Resource层代码,手动将同步结果转为响应式类型:

// 修改后的Quarkus Resource
@Inject
@RestClient
CommentRestClient commentRestClient;

@GET
@Path("/api/comments")
public Multi<Comment> apiCall() {
    return Multi.createFrom().iterable(commentRestClient.getComments());
}

方案3:排查自定义拦截器

如果确实需要在quarkus-rest-client中使用响应式类型,检查项目中是否存在自定义REST客户端拦截器,确保拦截器未对Uni/Multi类型进行不当处理,避免触发递归调用。

额外注意事项

  • Quarkus 3.x版本中,quarkus-rest-reactive-client已被quarkus-rest-client-reactive取代,优先使用后者可获得更好的兼容性和长期维护支持。
  • 确保application.properties中的配置key与@RegisterRestClient的configKey完全一致,避免配置失效。

内容的提问来源于stack exchange,提问作者TSSK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 01:05:02