JavaThinking.com
Toggle Menu
Home
Online Kotlin Compiler
Tutorials
Spring Boot
Spring Cloud
Spring Data
Spring MVC
Spring Security
Blog
All Posts
Spring Validation and Exception Handling
Test your grasp of validation frameworks and global exception handling.
1. Which annotation is used to trigger validation of a request body in Spring MVC?
@Valid
@Validate
@Validated
@Validation
2. Select all valid JSR-380 validation annotations (used for field-level constraints).
@NotNull
@Size
@Email
@Positive
@Valid
3. Spring's @ControllerAdvice annotation is used to handle exceptions globally across multiple controllers.
True
False
4. What is the full class name (without package) of the exception thrown when request body validation fails in Spring (e.g., missing @NotNull field)?
5. Which annotation is used to enable validation for controller method parameters (e.g., path variables, request parameters) at the class level in Spring?
@Valid
@Validated
@ControllerAdvice
@ExceptionHandler
6. Which of the following are valid approaches to handle exceptions in Spring MVC?
@ExceptionHandler annotation
@ControllerAdvice annotation
Extending ResponseEntityExceptionHandler
@Valid annotation
@ResponseStatus annotation
7. The @Size validation annotation can only be applied to String fields.
True
False
8. What attribute is used within validation annotations (e.g., @NotNull, @Size) to specify a custom error message?
9. Which interface must be implemented to create a custom validation constraint in Spring?
ConstraintValidator
Validator
CustomValidator
ValidationHandler
10. Which of the following are valid return types for a method annotated with @ExceptionHandler?
ModelAndView
ResponseEntity<?>
String (view name)
void
List<String>
Reset
Answered 0 of 0 — 0 correct