This article shows how to use Springs RestTemplate to consume a RESTful Service secured with Basic Authentication.
Since Spring 5.1.1 BasicAuthenticationInterceptor has been introduced for Basic Authentication.

import org.springframework.http.client.support.BasicAuthenticationInterceptor;
import org.springframework.web.client.RestTemplate;

//...

RestTemplate restTemplate = new RestTemplate();
restTemplate.getInterceptors().add(new BasicAuthenticationInterceptor("username", "password"));
restTemplate.exchange(
  "http://localhost:8082/spring-security-rest-basic-auth/api/foos/1", 
  HttpMethod.GET, null, Foo.class);

Code above will automatically add Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ= header.