C
C
Chvalov2018-03-26 03:47:14
Java
Chvalov, 2018-03-26 03:47:14

What dependencies should I include to validate Spring Boot forms?

Something I got confused with dependencies, I started to google how to properly validate the form, namely email fields, so as not to crutch with regular expressions.
Found a resource that says

We will need the validation-api-1.1.0.Final.jar and hibernate-validator-5.0.1.Final.jar files in order to use the Bean Validation API in our Spring MVC application.

maven pom
<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>1.1.0.Final</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>5.0.1.Final</version>
 </dependency>

And here I didn’t quite understand why add javax and hibernate validator dependencies if they are identical or not ?
If they are the same then I don't see the point.
And yet, as I understand spring-boot- xxxxx dependencies are inherited from other libraries
<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-validation</artifactId>
</dependency>

In particular, this spring-boot-starter-validation is inherited from hibernate-validator, if you look at this pom.xml
But even here it becomes unclear to me, if it is inherited from hibernate-validator, then why is javax.validation loaded in the code?
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

And another question, I noticed such a phenomenon in other people's projects
. Hibernate is used to work with the database, and Entity annotations use javax, but the IDE also offers similar dependencies from the hibernate package, what is the advantage of javax annotations over hiber?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
piatachki, 2018-03-26
@piatachki

This is the difference between specification and implementation. Java EE is specifications. Agreements on how to continue to live in the conditions of a ruthless bloody enterprise. JPA is part of it, one of the specifications, for example.
Hibernate is one of the JPA implementations. In my opinion, even RI. Why are annotations from the Javax package used? To make it easier for the author to change the Hibernate library to another one without rewriting the code. Therefore, ceteris paribus, it is recommended to use Java EE annotations.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question