In configuration (FFClientConfig.java), I have:
@Configuration
public class FFClientConfig {
...
@Bean //(name = "FFWebClient")
public WebClient FFApiWebClient(Jackson2JsonEncoder encoder,
Jackson2JsonDecoder decoder,
ExchangeFilterFunction errorHandler) {
return WebClient.builder().codecs(clientCodecConfigurer -> {
clientCodecConfigurer.defaultCodecs().jackson2JsonEncoder(encoder);
clientCodecConfigurer.defaultCodecs().jackson2JsonDecoder(decoder);
clientCodecConfigurer.defaultCodecs().maxInMemorySize(100000);
}).filter(errorHandler).build();
}
}
In another file (FFWebClient.java) I hope the bean defined above could be used for creating the instance of the component:
@Component
public class FFWebClient {
private final WebClient m_webClient;
public FFWebClient(WebClient webClient) {
m_webClient = webClient;
}
...
}
But I suspect the robustness of the code, because in the FFWebClient.java constructor, it doesn't indicate which WebClient instance to be used for constructor based bean injection, it could use either the default WebClient class to create an instance or, use the WebClient instance created by FFApiWebClient?
Shouldn't I use @Bean(name = "FFWebClient") to annotate the FFApiWebClient method? So that when using it, use @Qualifier to indicate that the FFWebClient bean is used instead of an instance created by the default WebClient class?