Recall & Review
beginner
What is a custom validator annotation in Spring Boot?
It is a user-defined annotation used to add specific validation rules to fields or methods beyond built-in validations.
Click to reveal answer
beginner
Which interface must be implemented to create a custom validator in Spring Boot?
The interface javax.validation.ConstraintValidator must be implemented to define the validation logic.
Click to reveal answer
intermediate
What two elements are required in a custom validator annotation definition?
1. @Target to specify where the annotation can be applied (e.g., fields). 2. @Retention to specify annotation lifetime (usually RUNTIME).
Click to reveal answer
intermediate
How do you link a custom annotation to its validator class?
Use the @Constraint(validatedBy = YourValidatorClass.class) annotation on the custom annotation definition.
Click to reveal answer
beginner
Why use custom validator annotations instead of simple methods?
They integrate with Spring Boot's validation framework, allowing automatic validation during data binding and clear error messages.
Click to reveal answer
What annotation is used to specify the validator class for a custom annotation?
✗ Incorrect
The @Constraint annotation links the custom annotation to its validator class.
Which method must be implemented in a ConstraintValidator?
✗ Incorrect
The isValid method contains the logic to check if the value is valid.
Where should a custom validator annotation be applied?
✗ Incorrect
Custom validator annotations are typically applied on fields or methods to validate their values.
What retention policy is usually used for custom validator annotations?
✗ Incorrect
RUNTIME retention allows the annotation to be available during program execution for validation.
Which package contains the ConstraintValidator interface?
✗ Incorrect
javax.validation.ConstraintValidator is the standard interface for custom validators.
Explain the steps to create a custom validator annotation in Spring Boot.
Think about annotation setup and validator class connection.
You got /5 concepts.
Why is it beneficial to use custom validator annotations instead of manual validation in Spring Boot?
Consider automation and reusability.
You got /4 concepts.