title: Spring Boot WebClient Builder initialization in ServiceImpl Constructor
body: <p>I am trying to follow the best practise of autowiring Webclient using WebClient Builder but little confused.</p>
  <p>Here is my Main Application in which i am producing a Webclient Builder and autowiring it in one of my service class</p>
  <pre><code> @SpringBootApplication
      public class MyApplication {
          @Bean
          public WebClient.Builder getWebClientBuilder() {
              return WebClient.builder();
          }
      
          public static void main(String[] args) {
              SpringApplication.run(MyApplication.class, args);
          }}
  
  
  ServiceImpl Class
  
      public class MyServiceImpl implements MyService {
          private static final String API_MIME_TYPE = &quot;application/json&quot;;
          private static final String API_BASE_URL = &quot;http://localhost:8080&quot;;
          private static final String USER_AGENT = &quot;Spring 5 WebClient&quot;;
          private static final Logger logger = LoggerFactory.getLogger(MyServiceImpl.class);
      
          @Autowired
          private WebClient.Builder webClientBuilder;
      
          @Override
          public Mono&lt;Issue&gt; createIssue(Fields field) {
              return webClientBuilder.build()
                      .post()
                      .uri(&quot;/rest/api/&quot;)
                      .body(Mono.just(field), Fields.class)
                      .retrieve()
                      .bodyToMono(Issue.class);
          }}
  </code></pre>
  <p>I am trying to build the webClientBuilder with BaseURl, DefaultHeader etc. I tried to initialize it inside MyServiceImpl Constructer but not sure if its correct or not.</p>
  <pre><code>public MyServiceImpl() {
              this.webClientBuilder
                      .baseUrl(API_BASE_URL).defaultHeader(HttpHeaders.CONTENT_TYPE, API_MIME_TYPE)
                      .defaultHeader(HttpHeaders.USER_AGENT, USER_AGENT)
                      .build();
          } 
  </code></pre>
  <p>Am i doing it correct or is there a better way to do it.</p>
  <p>Currently I have 2 ServiceImpls to call Different Apis and thats the reason i tried to set the 'baseurl' and other defaults in service itself.</p>
  <p>Please Help. TIA</p>