2.19.7. CDI 集成


在 MicroProfile REST 客户端中,您必须注释任何作为 CDI Bean 管理且具有 @RegisterRestClient 类的接口。例如:

@Path("resource")
@RegisterProvider(MyClientResponseFilter.class)
public static class TestResourceImpl {
      @Inject TestDataBase db;

      @Path("test/{path}")
      @Consumes("text/plain")
      @Produces("text/html")
      @POST
      public String test(@PathParam("path") String path, @QueryParam("query")
      String query, String entity) {
         return db.getByName(query);
      }
   }
   @Path("database")
   @RegisterRestClient
   public interface TestDataBase {

      @Path("")
      @POST
      public String getByName(String name);
   }

此处,MicroProfile REST 客户端实施为 TestDataBase 类服务创建一个客户端,让 TestResourceImpl 类能够轻松访问。但是,它不包括有关 TestDataBase 类实施路径的信息。此信息可以由可选 @Reg- isterProvider 参数 baseUri 提供:

@Path("database")
@RegisterRestClient(baseUri="https://localhost:8080/webapp")
public interface TestDataBase {
   @Path("")
   @POST
   public String getByName(String name);
}

这表示您可以访问 TestDataBase 的实现,地址https://localhost:8080/webapp。您还可以向外部提供以下系统变量信息:

<fully qualified name of TestDataBase>/mp-rest/url=<URL>

例如,以下命令表示您可以访问位于 https://localhost:8080/webapp 的 com.bluemondiamond.TestDatabase 类的实施:

com.bluemonkeydiamond.TestDatabase/mp-rest/url=https://localhost:8080/webapp
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.