10

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?

stevebot
  • 23,275
  • 29
  • 119
  • 181

4 Answers4

15

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.

Haakon
  • 1,741
  • 10
  • 19
9

Just for completeness, now it's also available the next versión of the spec, that's it JSR 349, which can be obtained with:

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

Hibernate Validator 5.x is the reference implementation for JSR 349 - Bean Validation 1.1 of which Red Hat is the specification lead.

togomez
  • 664
  • 6
  • 6
2

You should be able to get it from hibernate-validator.

Erich Douglass
  • 51,744
  • 11
  • 75
  • 60
2

It's not a spring annotation, it's from javaee and goes by javax.validation.Valid, hence the JSR reference.

Johan Sjöberg
  • 47,929
  • 21
  • 130
  • 148