Exception Handling
Exception handling with @ControllerAdvice, @ExceptionHandler, @ResponseStatus, error standardization
1What is @ControllerAdvice in Spring MVC?
What is @ControllerAdvice in Spring MVC?
Antwoord
@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.
2How to handle a specific exception in a controller?
How to handle a specific exception in a controller?
Antwoord
@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.
3What is the purpose of @ResponseStatus on an exception class?
What is the purpose of @ResponseStatus on an exception class?
Antwoord
@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.
Which exception is thrown when validation with @Valid fails?
What is ProblemDetail in Spring 6+?
+22 gespreksvragen
Andere Spring Boot-sollicitatieonderwerpen
Spring Core - IoC & DI
Spring Boot Auto-Configuration
Spring Boot Starters
Application Properties & YAML
Logging with SLF4J & Logback
Spring Boot DevTools
Spring MVC Basics
Spring REST Controllers
Request & Response Handling
Bean Validation
Spring Data JPA Basics
JPA Entities & Relationships
JPA Queries
Spring Data Repositories
Spring Security Basics
Spring Boot Actuator
Unit Testing with JUnit & Mockito
Spring Boot Testing
Profiles & Environment
RestTemplate & WebClient
Async & Scheduling
Caching with Spring
Spring WebFlux (Reactive)
Spring Transactions
Advanced Authentication & Authorization
JWT & Stateless Security
OAuth2 & Authorization Server
Spring Boot & Docker
Microservices with Spring
Spring Cloud Config
Performance Optimization
GraalVM Native Images
Beheers Spring Boot voor je volgende gesprek
Krijg toegang tot alle vragen, flashcards, technische tests, code review-oefeningen en gespreksimulatoren.
Begin gratis