title: How to fix RestTemplate NullPointerException in spring boot?
body: <pre><code>@Service
  public class RequestSender {
  
      private static final Logger logger = LoggerFactory.getLogger(RequestSender.class);
  
      @Autowired
      private RestTemplate restTemplate;
  
      public MbsFtResponseData sendJsonDataToMBS(final MBSTransactionData transactionData) {
          String mbsUrl = MBSConfigConstants.mbsUrl;
          try {
              logger.info("Sending request method Is Initiated");
              HttpEntity&lt;MBSTransactionData&gt; httpEntity = new HttpEntity&lt;&gt;(transactionData);
              ResponseEntity&lt;MbsFtResponseData&gt; response = restTemplate.exchange(mbsUrl, HttpMethod.POST, httpEntity,
                      MbsFtResponseData.class);
              if (response != null) {
                  HttpStatus status = response.getStatusCode();
                  if (status.is2xxSuccessful()) {
                      logger.info("Response getting back is succeded with the status code {}", status.value());
                      return response.getBody();
                  } else {
                      logger.error("ERROR Response getting back is  with the status code {}", status.value());
                      throw new BBPSMBSException("Error is while connecting to mBS server", status.value());
                  }
              } else {
                  logger.error("Null value::::::::::::response is null");
              }
          } catch (Exception e) {
              e.printStackTrace();
              logger.error("ERROR :::{}:: is occered ", e.getCause());
          }
          return new MbsFtResponseData("Server Not responding or Busy", 500, "FAILED");
      }
  }
  </code></pre>
  
  <pre><code>java.lang.NullPointerException  at com.npst.bbps.middleware.mbs.RequestSender.sendJsonDataToMBS(RequestSender.java:26)  at com.npst.bbps.middleware.mbs.MbsftServiceImpl.mbsFundTransfer(MbsftServiceImpl.java:27)  at com.npst.bbps.middleware.controller.ThirdPartyIntegrationCtrl.initiateRefund(ThirdPartyIntegrationCtrl.java:64)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  </code></pre>