Spring Boot

Exception Handling

Exception handling with @ControllerAdvice, @ExceptionHandler, @ResponseStatus, error standardization

25 면접 질문·
Mid-Level
1

What is @ControllerAdvice in Spring MVC?

답변

@ControllerAdvice allows centralizing exception handling for all application controllers. This annotation creates a global component that intercepts exceptions thrown by any @Controller or @RestController. This avoids duplicating error handling logic in each controller and promotes error response consistency.

2

How to handle a specific exception in a controller?

답변

@ExceptionHandler allows defining a method that handles one or more specific exceptions in a controller or @ControllerAdvice. The annotated method is automatically invoked when the specified exception is thrown. It's possible to return a ResponseEntity to control the HTTP status and response body.

3

What is the purpose of @ResponseStatus on an exception class?

답변

@ResponseStatus on a custom exception allows automatically mapping this exception to a specific HTTP status code. When the exception is thrown, Spring automatically returns the indicated HTTP status without requiring an @ExceptionHandler. This approach simplifies code for simple exceptions that directly correspond to an HTTP status.

4

Which exception is thrown when validation with @Valid fails?

5

What is ProblemDetail in Spring 6+?

+22 면접 질문

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

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

무료로 시작하기