Apache CXF 缺少 WebClient class?
WebClient class missing from Apache CXF?
我目前正在使用 Apache CXF 版本 3.1.11 构建 JAX-RS 客户端。我一直在网上查看一些简单的示例,WebClient class 似乎不见了。
参见下面我在网上找到的示例代码。
public static void main(String[] args) throws JsonParseException,
JsonMappingException, IOException {
WebClient client = WebClient
.create("http://localhost:8080/",
Collections.singletonList(new JacksonJsonProvider()))
.path("test").accept(MediaType.APPLICATION_JSON_TYPE);
Message message = client.get(Message.class);
System.out.println("Message recieved : " + message);
}
我在代码中的任何地方都找不到 WebClient class,我正在使用以下 Maven 依赖项。
- cxf-rt-前端-jaxws
- cxf-rt-transports-http
- cxf-rt-transports-http-jetty
请有人确认我是否缺少依赖项,或者 WebClient 是否已从版本 3.1.11 中删除
如果您不确定具体的提供程序实现,您可以使用 类,它们是 JAX-RS 的标准部分,它们是 [=15] =]Client
和 WebTarget
。但是对于编组,当然,您可能仍然需要配置特定的依赖项,可以手动配置,也可以由 Apache CXF.
提供
Client client = ClientBuilder.newBuilder().build();
WebTarget target = client
.target("http://localhost:8080/");
Response response = target.request().get();
Message message = client.readEntity(Message.class);
/*
// now.. process the message
for (Message message : message.get...) {.. }
*/
response.close(); // close connections.
您需要添加 cxf-rt-frontend-jaxrs 而不是 cxf-rt-frontend-jaxws
我目前正在使用 Apache CXF 版本 3.1.11 构建 JAX-RS 客户端。我一直在网上查看一些简单的示例,WebClient class 似乎不见了。
参见下面我在网上找到的示例代码。
public static void main(String[] args) throws JsonParseException,
JsonMappingException, IOException {
WebClient client = WebClient
.create("http://localhost:8080/",
Collections.singletonList(new JacksonJsonProvider()))
.path("test").accept(MediaType.APPLICATION_JSON_TYPE);
Message message = client.get(Message.class);
System.out.println("Message recieved : " + message);
}
我在代码中的任何地方都找不到 WebClient class,我正在使用以下 Maven 依赖项。
- cxf-rt-前端-jaxws
- cxf-rt-transports-http
- cxf-rt-transports-http-jetty
请有人确认我是否缺少依赖项,或者 WebClient 是否已从版本 3.1.11 中删除
如果您不确定具体的提供程序实现,您可以使用 类,它们是 JAX-RS 的标准部分,它们是 [=15] =]Client
和 WebTarget
。但是对于编组,当然,您可能仍然需要配置特定的依赖项,可以手动配置,也可以由 Apache CXF.
Client client = ClientBuilder.newBuilder().build();
WebTarget target = client
.target("http://localhost:8080/");
Response response = target.request().get();
Message message = client.readEntity(Message.class);
/*
// now.. process the message
for (Message message : message.get...) {.. }
*/
response.close(); // close connections.
您需要添加 cxf-rt-frontend-jaxrs 而不是 cxf-rt-frontend-jaxws