Java HttpClient for Spring Web Client Spring Boot Starter

Java HttpClient support for Spring WebClient

Лицензия

Лицензия

Категории

Категории

Java Языки программирования Spring Boot Контейнер Микросервисы CLI Взаимодействие с пользователем
Группа

Группа

com.integralblue
Идентификатор

Идентификатор

java-httpclient-webclient-spring-boot-starter
Последняя версия

Последняя версия

1.0.0
Дата

Дата

Тип

Тип

pom.sha512
Описание

Описание

Java HttpClient for Spring Web Client Spring Boot Starter
Java HttpClient support for Spring WebClient
Ссылка на сайт

Ссылка на сайт

https://github.com/candrews/java-httpclient-webclient-spring-boot-starter
Система контроля версий

Система контроля версий

https://github.com/candrews/java-httpclient-webclient-spring-boot-starter

Скачать java-httpclient-webclient-spring-boot-starter

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

Java HttpClient for Spring Web Client Boot Starter

javadoc Maven Central GitHub

The Java HttpClient for Spring Web Client Boot Starter provides a quick and easy way to use Java 11's HttpClient as Spring WebClient's client HTTP connector.

By default, Spring WebClient will try to use Reactor Netty then Jetty Client as it's client HTTP connector. This starter will instead use Java 11's HTTP client.

Benefits of using this starter include:

  • not needing additional dependencies such as on Netty or Eclipse
  • getting the benefits and features of Java's built in HttpClient
  • Being able to use tooling for Java's HttpClient, such as HttpClientMock

Using This Starter

To use this starter, you need:

  • Java 11 (or later)
  • Spring Boot 2.3.0 (or later)
  • Spring WebClient, which is included in Spring WebFlux

Add the Dependency

Add a dependency on this starter your dependency manager of choice, making sure to use the latest version: Maven Central

For Gradle:

dependencies {
	runtimeOnly 'com.integralblue:java-httpclient-webclient-spring-boot-starter:VERSION'
}

For Maven:

<dependency>
	<groupId>com.integralblue</groupId>
	<artifactId>java-httpclient-webclient-spring-boot-starter</artifactId>
	<version>VERSION</version>
    <scope>runtime</scope>
</dependency>

Use the Autowired WebClient.Builder

Follow the advice given in the Spring Boot documentation under Calling REST Services with WebClient when using WebClient by autowiring an instance of WebClient.Builder and using that to create the WebClient instance.

For example:

@Service
public class MyService {

    private final WebClient webClient;

    public MyService(WebClient.Builder webClientBuilder) {
        this.webClient = webClientBuilder.baseUrl("https://example.org").build();
    }

    public Mono<Details> someRestCall(String name) {
        return this.webClient.get().uri("/{name}/details", name)
                        .retrieve().bodyToMono(Details.class);
    }

WebClient.create() and WebClient.builder().build() will not apply the customizations from this starter meaning WebClients created using those approaches will not use Java 11's HttpClient.

Future of This Starter

Eventually, a future version of Spring will likely include this functionality. Follow the Pull Request for JDK 11 HttpClient integration with WebClient for more information.

Developing the Starter

This project requires Java 11 (or later). Import this Gradle project using your IDE of choice. Or, if you don't want to use an IDE, you can run the project from the command line: ./gradlew build The test suite will run and a jar will be output at build/libs/.

Eclipse

The Project Lombok Eclipse integration must be setup. See the Eclipse instructions on Project Lombok's site.

Версии библиотеки

Версия
1.0.0
0.0.11