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

Quarkus扩展中使用Rest Client Reactive触发UnsatisfiedResolutionException如何解决

Quarkus扩展中使用Rest Client Reactive的正确方案

你遇到的UnsatisfiedResolutionException异常是因为Quarkus扩展的类扫描逻辑和普通应用不同,普通应用中加了@RegisterRestClient的接口会被自动注册为CDI Bean,但扩展中的Rest Client接口需要显式通过扩展SPI注册才能被识别。


1. 确认依赖配置

首先确保两个模块都引入了正确的Rest Client Reactive依赖:

  • runtime模块pom.xml:
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-rest-client-reactive</artifactId>
</dependency>
  • deployment模块pom.xml:
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-rest-client-reactive-deployment</artifactId>
    <scope>provided</scope>
</dependency>

2. 修改deployment模块的BuildStep逻辑

需要新增RestClientBuildItem的生产,显式注册你的Rest Client接口,修改后的代码如下:

@BuildStep
protected void registerExtensionBeans(BuildProducer<AdditionalBeanBuildItem> additionalBeans,
                                      BuildProducer<RestClientBuildItem> restClientProducer) {
    // 注册原有业务Bean
    additionalBeans.produce(AdditionalBeanBuildItem.builder()
            .addBeanClass(DiscoveryProvider.class)
            .setUnremovable()
            .build());
    // 显式注册Rest Client接口
    restClientProducer.produce(new RestClientBuildItem(DiscoveryOpenApi.class));
}

3. 确认注解配置无误

  • 你当前DiscoveryProvider中只保留@RestClient注解即可,不需要额外加@Inject,@RestClient本身已经自带注入语义
  • 确认DiscoveryOpenApi上的@RegisterRestClient注解包路径正确,你当前使用的是javax体系,对应的包为org.eclipse.microprofile.rest.client.annotation.RegisterRestClient
  • 确认@RestClient的包路径为org.eclipse.microprofile.rest.client.inject.RestClient,不要导错包

4. 配置Rest Client访问地址

因为你设置了configKey="discovery.nacos",需要在使用扩展的应用配置文件(application.properties)中添加对应的地址配置:

quarkus.rest-client.discovery.nacos.url=http://你的Nacos服务地址:8848/nacos
# 可选配置 超时、重试等
quarkus.rest-client.discovery.nacos.connect-timeout=5000
quarkus.rest-client.discovery.nacos.read-timeout=10000

如果需要给扩展设置默认配置,可以在runtime模块的META-INF/quarkus-extension.properties中添加默认值,用户可自行在应用配置中覆盖。

注意事项

不要手动给DiscoveryOpenApi接口添加@ApplicationScoped等作用域注解,Rest Client的Bean注册逻辑由Quarkus Rest Client扩展统一处理,手动添加会导致冲突。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 08:36:04