0

If I want to send some request to a microservice under the gateway (for example, trigger by a timer), should I build a new WebClient, or just use an existing bean?

Bill Billy
  • 137
  • 12
  • WebClient is thread-safe, so it is an appropriate method to use WebClient as a bean. See [this](https://stackoverflow.com/questions/49095366/right-way-to-use-spring-webclient-in-multi-thread-environment). – chytonpide Jun 08 '22 at 02:14
  • Should I build a WebClient bean by myself, or could I just use some client/handler bean provided by Spring Cloud Gateway? – Bill Billy Jun 08 '22 at 02:39
  • Like all the other beans, you have to create an instance of WebClient as a bean in your spring configuration. it seems like below. This is, of course, a simplified example and various properties can be set when creating a WebClient. `@Configuration public class WebClientConfig { @Bean public WebClient webClient() { return WebClient.create(); } }` – chytonpide Jun 08 '22 at 03:28

0 Answers0