In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to invoke REST service WebClient in Spring Boot2". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Invoke the REST service WebClient
If you have Spring WebFlux on your classpath, you can also choose to use WebClient to invoke remote REST services. Compared with RestTemplate, this customer has a more functional sense and is completely passive. You can use the builder to create your own client instance, WebClient.create (). Please refer to the relevant section on WebClient.
Spring Boot creates and preconfigures such a builder for you. For example, the client HTTP codec is configured in the same way as the server (see WebFlux HTTP codec autoconfiguration).
The following code shows a typical example:
1@Service
2public class MyService {
3private final WebClient webClient
4public MyBean (WebClient.Builder webClientBuilder) {
5this.webClient = webClientBuilder.baseUrl ("http://example.org").build();
6}
7public Mono someRestCall (String name) {
8return this.webClient.get () .url ("/ {name} / details", name)
9.retrieve () bodyToMono (Details.class)
10}
11}
WebClient customization
There are three main ways to customize WebClient, depending on the scope of your application.
To minimize the scope of any customization, inject the autoconfiguration WebClient.Builder, and then call its methods as needed. The WebClient.Builder instance is stateful: any changes on the builder are reflected in all clients subsequently created with it. If you want to create multiple clients using the same builder, you can also consider using the clone builder WebClient.Builder other = builder.clone ();.
To make additional application-wide customization for all WebClient.Builder instances, you can declare WebClientCustomizerbean and WebClient.Builder to make changes locally at the injection point.
Finally, you can go back to the original API and use WebClient.create (). In this case, there is no automatic configuration or WebClientCustomizer application.
This is the end of the content of "how to invoke REST Service WebClient in Spring Boot2". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.