Java Apache CXF中缺少WebClient类?
我目前正在使用ApacheCXF版本3.1.11构建一个JAX-RS客户机。我一直在网上看一些简单的例子,似乎WebClient类已经丢失了 请参阅下面我在网上找到的示例代码Java Apache CXF中缺少WebClient类?,java,apache,jax-rs,cxf,Java,Apache,Jax Rs,Cxf,我目前正在使用ApacheCXF版本3.1.11构建一个JAX-RS客户机。我一直在网上看一些简单的例子,似乎WebClient类已经丢失了 请参阅下面我在网上找到的示例代码 public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException { WebClient client = WebClient .c
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);
}
我在代码和im中的任何地方都找不到WebClient类,使用以下maven依赖项
- cxf rt前端jaxws
- cxf rt传输http
- cxf rt传输http jetty
请有人确认我是否缺少依赖项,或者WebClient是否已从3.1.11版中删除。如果您不确定具体的提供程序实现,您可以使用JAX-RS的标准部分类,它们是duo
Client
和WebTarget
。但是对于编组,当然,您可能仍然需要配置特定的依赖项,可以手动配置,也可以由ApacheCXF提供
您需要添加cxf rt前端-jaxrs而不是cxf rt前端jaxws
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.