Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What setup do I need to do to use JSR-303 annotations with Spring?

I downloaded spring 3 and put it on my classpath but I'm not able to import the @Valid annotation. However, I am able to import other spring 3 annotations (such as @Controller). What Jar is @Valid in and what package?

EDIT: This is a JSR-303 annotation. What does that mean and how do I get it?

like image 850
stevebot Avatar asked Feb 25 '11 22:02

stevebot


People also ask

What is the use of @validated in Spring boot?

@Validated annotation is a class-level annotation that we can use to tell Spring to validate parameters that are passed into a method of the annotated class. @Valid annotation on method parameters and fields to tell Spring that we want a method parameter or field to be validated.


1 Answers

javax.validation is missing.

You'll find a jar here. If you use Maven, this is the dependency:

<dependency>
  <groupId>javax.validation</groupId>
  <artifactId>validation-api</artifactId>
  <version>1.0.0.GA</version>
</dependency>

For validation to actually work, you need an implementation as well, such as Hibernate Validator. Maven dependency:

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-validator</artifactId>
  <version>4.0.2.GA</version>
  <scope>runtime</scope>
</dependency>

The JSR reference means that this is a standard developed by the Java Community Process, specifically JSR number 303.

like image 131
Haakon Avatar answered Sep 22 '22 08:09

Haakon