- Annotations are introduced in java along with JDK 1.5, annotations are used to provide META data to the classes, variables, methods of java
- Annotations are given by SUN as replacement to the use of xml files in java
- Every annotations is internally an Interface, but the key words starts with @ symbol
- In hibernate annotations are given to replace hibernate mapping [ xml ] files
- hibernate borrowed annotations from java persistence API but hibernate it self doesn’t contain its own annotations
- At j2se level, sun has provided very limited set of annotations like @Override and @Deprecated …etc…
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
import XXX.AbcImpl;
// This annotation can only be applied to class methods.
// @Target({ElementType.METHOD})
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, ElementType.TYPE })// Make this annotation accessible at runtime via reflection.
@Retention(RUNTIME)@Constraint(validatedBy = AbcImpl.class)
public @interface Abc {
public String message() default "{wc.def.notempty.on.trim}";
Class<?>[] groups() default { };
Class<? extends Payload>[] payload() default {};
}
Now is annotated, so we can call this as a @Abc.
No comments:
Post a Comment