javaspring-bootjavax.validationjakarta-validation

Jakarata validation compatibility for SpringBoot 2.x


There is a service which uses SpringBoot 2.2 and previously it uses javax default validations. However due to some other newly added dependency, jakarta validation had to be added as well. Now, existing javax validations are not working due to name space conflict issues. Following things were tried for using Jakarta instead of Javax and none worked.

  1. Remove javax valdation by excluding spring boot validation from spring boot web
  2. Upgrade the service to SpringBoot 2.3

Some articles say that Jakarta validation is supported only for SpringBoot 3.x versions - Having such an upgrade from 2.2 to 3.x is not possible right now. And some other articles say that the Jakarta validation should work SpringBoot 2.3+

What is the most effective solution for this?


Solution

  • This quite a hard problem to solve, there are a few options that you can look into.

    1. Find an older version of the library that required the jakarta validation.
    2. Try and manage the two dependencies next to each other which is a nightmare on it's own.
    3. Find a way to do the upgrades anyways.

    Even though option 3 is the most unsatisfying answer I would still recommend you to move as soon as possible to at least a supported version. See https://spring.io/projects/spring-boot#support for which versions are supported. As you can see on the spring boot versions page your service is already 4 years out of support which is a enormous security risk on it's own.

    To help you with your upgrade journey I would like to point you towards Openrewrite which is a tool that helps you migrate your application. This tool has both recipes for upgrading to java 17 as for upgrading from spring boot 2.7 to 3.0 and beyond.