0

In my Quarkus extension, I want to use REST Client Reactive, but an exception occurred in the run log :

Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type cn.ecpark.quarkus.extension.discovery.DiscoveryOpenApi and qualifiers [@RestClient]
    - java member: cn.ecpark.quarkus.extension.discovery.DiscoveryProvider#discoveryOpenApi
    - declared on CLASS bean [types=[cn.ecpark.quarkus.extension.discovery.DiscoveryProvider, java.lang.Object], qualifiers=[@Default, @Any], target=cn.ecpark.quarkus.extension.discovery.DiscoveryProvider]

deployment module code snippet:

@BuildStep
protected void additionalBeans(BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
   additionalBeans.produce(AdditionalBeanBuildItem.builder()
           .addBeanClass(DiscoveryProvider.class)
           .setUnremovable().build());
}

runtime module code snippet:

@ApplicationScoped
public class DiscoveryProvider {
//    @Inject
    @RestClient
    DiscoveryOpenApi discoveryOpenApi;
}
@Path("/v1/ns/")
@RegisterRestClient(configKey="discovery.nacos")
public interface DiscoveryOpenApi {

    @POST
    @Path("/instance")
    @Produces(MediaType.TEXT_PLAIN)
    Uni<String> registerInstance(@QueryParam("namespaceId") String namespaceId, @QueryParam("groupName") String groupName, @QueryParam("serviceName") String serviceName,
                                 @QueryParam("clusterName") String clusterName, @QueryParam("ip") String ip, @QueryParam("port") @DefaultValue("0") Integer port,
                                 @QueryParam("weight") Double weight, @QueryParam("enabled") Boolean enabled, @QueryParam("healthy") Boolean healthy,
                                 @QueryParam("metadata") String metadata, @QueryParam("ephemeral") Boolean ephemeral);
}

How should I use Rest Client when developing a plug-in?

liuz
  • 1
  • The fact that you have to register `DiscoveryProvider` as an additional bean suggests that it isn't present in a bean archive. Perhaps `DiscoveryOpenApi` isn't present in a bean archive either and must be registered as an additional bean too? – Ladicek Oct 22 '21 at 07:16
  • Do you know how to register a REST Client interface as an additional bean, I used the following method, but the error still exists `@BuildStep protected void additionalBeans(BuildProducer additionalBeans) { additionalBeans.produce(AdditionalBeanBuildItem.builder() .addBeanClass(DiscoveryOpenApi.class) .setUnremovable().build()); additionalBeans.produce(AdditionalBeanBuildItem.builder() .addBeanClass(DiscoveryProvider.class) .setUnremovable().build()); }` – liuz Oct 22 '21 at 08:48
  • Actually no, I don't. RestClient interfaces are special and my advice to register the interface as an additional bean was probably too simple to actually work. Maybe there's a `BuildItem` to register and additional RestClient, not sure. Alternatively, instead of registering additional beans, you may add a `META-INF/beans.xml` file to your JAR. I assume it is a `runtime` portion of a Quarkus extension, in which case, it is not exactly common, but it's been done before and should work just fine. – Ladicek Oct 22 '21 at 12:25
  • Thank you for your reply, I will try other BuildItem to solve the problem – liuz Oct 23 '21 at 13:53
  • @liuz if you have the whole project somewhere, I'll be happy to take a look. – Michał Szynkiewicz Nov 04 '21 at 11:16

0 Answers0