Scrivio Interview library
ConceptFoundations5 min read · updated 12 November 2026

What is Bean Validation, and what do you need in a Spring Boot 3 project to use annotations like @NotBlank?

Bean Validation, now called Jakarta Validation, is a Java standard that defines constraint annotations such as @NotBlank and @Size and an API to check objects against them; Hibernate Validator is the implementation almost everyone uses. In a Spring Boot 3 project we add spring-boot-starter-validation, because the web starter does not include it, and we import the annotations from jakarta.validation.constraints. Without a provider on the classpath, the annotations are simply ignored and no error tells us.

Why this question is asked

Almost every REST API validates its input, and Bean Validation is how Spring applications usually do it: we annotate a DTO and Spring rejects bad requests before our code runs. The first time many developers set it up, though, nothing happens: invalid data goes straight through, because a dependency is missing or an import is wrong. Interviewers ask this question to check that we know what the standard is, what actually does the work, and how it is wired into Spring Boot. In this answer, we will recap what Bean Validation is, set up a Boot 3 project, see validation working on a request, and look at the silent failure when the provider is missing.

1A Quick Recap of Bean Validation

Bean Validation is a specification, a document plus a set of interfaces, that says how to declare rules on Java objects with annotations and how to check them. It started as JSR 303 in 2009, became Jakarta Bean Validation when Java EE moved to the Eclipse Foundation, and is now usually called Jakarta Validation. The specification gives us constraint annotations such as @NotNull, @NotBlank, @Size, @Email, @Min and @Positive, and the Validator interface that checks an object and returns a set of violations.

A specification on its own does nothing; it needs an implementation, also called a provider. Hibernate Validator is the reference implementation and the one Spring Boot uses. It is a separate project from Hibernate ORM, so we can use it without JPA. The separation matters: our code depends only on the jakarta.validation annotations, and the provider reads them at runtime.

Step throughWho does what in validation
  1. Our DTOfields annotated with @NotBlank, @Size, @Email
  2. Spring MVCsees @Valid on a parameter and asks a Validator
  3. Jakarta Validation APIjakarta.validation: annotations and Validator interface
  4. Hibernate Validatorthe provider: reads annotations, runs the checks

4 layers, from the top down. Step through them one at a time.

2Setting Up a Spring Boot 3 Project

Since Spring Boot 2.3, spring-boot-starter-web no longer brings validation with it, so we add the validation starter ourselves. It brings Hibernate Validator and the Jakarta Validation API, and Boot auto-configures a validator bean that Spring MVC uses.

XML
<!-- pom.xml -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
// The DTO, with Boot 3 imports
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
public record CreateCustomer(
@NotBlank @Size(max = 100) String name,
@Email String email) {}

Notice the package. Spring Boot 3 moved from Java EE to Jakarta EE, so the annotations live in jakarta.validation.constraints. Old tutorials and copied code still use javax.validation.constraints, and if an old javax validation jar happens to be on the classpath, the code compiles but Hibernate Validator 8 and later do not recognise those annotations, so they are silently skipped. With Boot 3 we get Hibernate Validator 8 on Jakarta Validation 3.0, and Boot 4 moves to newer versions of both; check your version if an exact number matters.

3Seeing Validation Work on a Request

Validation is triggered by @Valid on the controller parameter. Spring binds the JSON into the record, asks the validator to check it, and rejects the request if there are violations.

Java
@PostMapping("/customers")
ResponseEntity<Customer> create(@Valid @RequestBody CreateCustomer body) {
return ResponseEntity.status(201).body(service.create(body));
}
// POST /customers {"name": " ", "email": "not-an-email"}
// -> 400 Bad Request, MethodArgumentNotValidException
// name: must not be blank
// email: must be a well-formed email address

The method body never runs for the invalid request. Spring throws MethodArgumentNotValidException, which becomes a 400 response; with spring.mvc.problemdetails.enabled=true or a @ControllerAdvice extending ResponseEntityExceptionHandler, we can return the field errors in a ProblemDetail body. We can also use the validator directly in a test or a service by injecting jakarta.validation.Validator and calling validate(object), which returns the set of violations.

4When the Provider Is Missing

Now remove the validation starter and send the same invalid request. It succeeds. The annotations are still in the code, @Valid is still on the parameter, but there is no provider, so Spring MVC has no real validator to call and quietly skips the step.

Java
// Without spring-boot-starter-validation on the classpath
// POST /customers {"name": " ", "email": "not-an-email"}
// -> 201 Created (no validation happened, no warning in the log)
@SpringBootTest
@AutoConfigureMockMvc
class CustomerValidationTest {
@Autowired MockMvc mvc;
@Test void blankNameIsRejected() throws Exception {
mvc.perform(post("/customers").contentType(APPLICATION_JSON).content("{\"name\":\" \"}"))
.andExpect(status().isBadRequest()); // fails loudly if validation is not wired
}
}

This is the dangerous part: annotations are just metadata, and Java never complains that nobody reads them. So the safeguard is a test like the one above for at least one invalid request per API. It turns a missing dependency, a wrong import or a forgotten @Valid into a failing build instead of bad data in the database.

5Follow-up questions

Is Hibernate Validator tied to Hibernate ORM or JPA?

No. It shares the Hibernate name and community, but it is an independent library. It works in any Java application. JPA providers can also run Bean Validation automatically before inserting or updating an entity, which is a second, separate place where the same annotations are checked.

Do we need spring-boot-starter-validation for @Validated method validation too?

Yes. Method validation on Spring beans, enabled by @Validated on a class, uses the same provider. Without it, Boot does not create the MethodValidationPostProcessor, so constraints on service method parameters are ignored as well.

Where do the default messages such as must not be blank come from?

From the provider's resource bundle, ValidationMessages.properties inside Hibernate Validator, translated for many locales. We can override them per constraint with the message attribute, or globally by adding our own ValidationMessages.properties to the classpath.

6Conclusion

In this answer, we saw that Bean Validation, now Jakarta Validation, is a standard for constraint annotations and a validation API, and that Hibernate Validator is the provider that does the work. In Spring Boot 3 we add spring-boot-starter-validation because the web starter does not include it, and we import annotations from jakarta.validation.constraints. Without a provider, @NotBlank and @Valid are silently ignored, so a test with one invalid request is worth writing.

What to say in the interviewAbout 70 seconds aloud

Open with

Bean Validation, which is now called Jakarta Validation, is a Java specification. It defines constraint annotations like @NotNull, @NotBlank, @Size and @Email, and a Validator API that checks an object and returns the violations.

Then, if they want more

The specification itself does not run anything, so we need a provider, and in practice that is Hibernate Validator, which is the reference implementation and independent of Hibernate ORM. In a Spring Boot 3 project I add spring-boot-starter-validation, because since Boot 2.3 the web starter does not include it.

That brings Hibernate Validator, and Boot auto-configures a validator that Spring MVC uses when a parameter has @Valid, for example @Valid @RequestBody. If validation fails, Spring throws MethodArgumentNotValidException and returns 400. The annotations come from jakarta.validation.constraints in Boot 3, not the old javax package.

The important trap is that without a provider on the classpath, nothing fails: the annotations are just metadata and Spring silently skips validation, so invalid data goes straight through. That is why I always add at least one test that sends an invalid request and expects 400.

About this answer

Last updated
12 November 2026
Versions it names
Spring Boot 3, Spring Boot 2.3
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is Bean Validation, and what do you need in a Spring Boot 3 project to use...": https://scrivio-interview-library.netlify.app/spring-boot/request-validation/5fe491f68d/