使用Jersey客戶端請求Spring Boot服務可以通過以下步驟實現:
<!-- Jersey Client -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.34</version>
</dependency>
ClientBuilder
類創建一個客戶端實例:Client client = ClientBuilder.newClient();
HttpAuthenticationFeature
類設置認證信息:HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("username", "password");
client.register(feature);
WebTarget target = client.target("http://localhost:8080/api/resource");
Response response = target.request()
.header("Content-Type", "application/json")
.post(Entity.json(requestBody));
int statusCode = response.getStatus();
String responseBody = response.readEntity(String.class);
client.close();
以上是使用Jersey客戶端請求Spring Boot服務的基本步驟。根據你的具體需求,你可能需要添加更多的配置和處理邏輯。