Custom Class Level Validation - Creating the Annotation

Sandro Rey :

I want to implement a custom validator in a Spring Boot v1.5.14.RELEASE app. First I create a custom constraint annotation:

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public interface CreateBook {
}

However, I receive this compilation error:

@Retention not applicable to type
Amongalen :

The problem is with how you define a new annotation. It should be like this:

@Retention(RetentionPolicy.RUNTIME)
public @interface CreateBook {
}

Note the @ character in @interface

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326875&siteId=1