我遵循了 Quarkus 网站上的其余客户端指南。它工作正常。但是,当使用 ServiceLoader 模式注册全局提供程序时,如规范中所述,CDI bean 注入不起作用,它们都是空的。我下载了示例并简单地添加了以下类:
package org.acme.rest.client;
import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper;
import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.core.Response;
@ApplicationScoped
public class MyExceptionMapper implements ResponseExceptionMapper<Exception> {
@Override
public Exception toThrowable (Response response) {
return new Exception();
}
}
package org.acme.rest.client;
import org.eclipse.microprofile.rest.client.RestClientBuilder;
import org.eclipse.microprofile.rest.client.spi.RestClientBuilderListener;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
@ApplicationScoped
public class MyListener implements RestClientBuilderListener {
@Inject MyExceptionMapper myExceptionMapper;
@Override
public void onNewBuilder (RestClientBuilder builder) {
builder.register(myExceptionMapper);
}
}
我还添加了内容为 org.acme.rest.client.MyListener 的文件 META-INF/services/org.eclipse.microprofile.rest.client.spi.RestClientBuilderListener。调用了 MyListener onNewBuilder 方法,但注入的提供程序 MyExceptionMapper 为 null。如何在 Quarkus 客户端注册全球提供商?