Spring Boot

RestTemplate & WebClient

HTTP calls with RestTemplate (synchronous) and WebClient (reactive), error handling, interceptors

24 면접 질문·
Mid-Level
1

What is the status of RestTemplate in recent Spring versions?

답변

RestTemplate has been in maintenance mode since Spring 5 and is no longer actively developed. Spring recommends using WebClient, a more modern and performant non-blocking reactive API. RestTemplate remains supported for compatibility with existing code, but new projects should prefer WebClient.

2

Which RestTemplate method returns only the response body?

답변

getForObject directly returns the deserialized object from the HTTP response body, without metadata (status, headers). This method is convenient for simple cases where only data is needed. To access headers or HTTP status, use getForEntity which returns a complete ResponseEntity.

3

Which RestTemplate method allows access to the HTTP status and response headers?

답변

getForEntity returns a ResponseEntity that encapsulates the response body, HTTP status code and headers. This method is useful when it's necessary to inspect response metadata, such as checking the status or reading a custom header. For simple cases where only the body is needed, getForObject is sufficient.

4

Which RestTemplate method offers the most control over the HTTP request?

5

Which component allows customization of HTTP error handling in RestTemplate?

+21 면접 질문

다음 면접을 위해 Spring Boot을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기