HttpHeaders headers = new HttpHeaders(); headers.setBasicAuth(username, password); HttpHeaders headers = new HttpHeaders(); headers.setBasicAuth(username, password); then continue with the same procedure mentioned by the others here:
HttpEntity<String> request = new HttpEntity<String>(headers); ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, request, String.class); HttpEntity<String> request = new HttpEntity<String>(headers); ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, request, String.class);