Spring Boot

Request & Response Handling

@PathVariable, @RequestParam, @RequestBody, @RequestHeader, content negotiation, JSON serialization

20 preguntas de entrevista·
Mid-Level
1

Which annotation allows extracting a value from an HTTP header in a Spring MVC controller?

Respuesta

@RequestHeader allows extracting values from HTTP headers of the incoming request. This annotation automatically binds the value of a specific header to a method parameter. It supports type conversions and can be made optional with required=false. Useful for extracting authentication tokens, tracking information or client preferences like Accept-Language.

2

How to retrieve the value of a cookie named 'sessionId' in a controller method?

Respuesta

@CookieValue allows extracting the value of a specific HTTP cookie and binding it to a method parameter. The annotation accepts the cookie name as a parameter and supports automatic type conversions. It can also be marked as optional with required=false. Commonly used for session identifiers, user preferences or analytics tracking tokens.

3

Why is injecting HttpServletRequest directly into a controller method less optimal than using Spring MVC annotations?

Respuesta

Spring MVC annotations like @RequestParam, @RequestHeader or @PathVariable offer typed and automatic data extraction, with conversion and validation handling. Using HttpServletRequest directly requires manual parsing, makes code less readable and testable. Annotations also promote immutability and API contract clarity.

4

Which interface allows intercepting HTTP requests before they reach the controller in Spring MVC?

5

How to register a custom interceptor in a Spring MVC application?

+17 preguntas de entrevista

Domina Spring Boot para tu próxima entrevista

Accede a todas las preguntas, flashcards, tests técnicos, ejercicios de code review y simuladores de entrevista.

Empieza gratis