Search code examples
spring-bootbean-validationjakarta-migration

Spring Boot 3.0 package javax.validation does not exist


I'm trying to use a method parameter validation feature supported by Bean Validation 1.1. For instance, the following method triggers the validation of the first parameter, making sure it's valid:

public String generateOtp(@Valid TotpAuthenticatorForm form, BindingResult bindingResult)

When I build a Spring Boot 2.7.7 project it's fine, but building a Spring Boot 3.0.1 project fails with a compilation error:

package javax.validation does not exist

How do I fix the issue?


Solution

  • According to the release-notes, Spring Boot 3.0 has migrated from Java EE to Jakarta EE APIs for all dependencies, including:

    Jakarta Validation 3.0
    
    • Spring Boot 2.7 - Jakarta Bean Validation 2.0
    • Spring Boot 3.0 - Jakarta Bean Validation 3.0

    You can fix the issue by using Jakarta Bean Validation 3.0. Simply update import statements:

    javax.validation
    ->
    jakarta.validation