Sandro Rey
Sandro Rey

Reputation: 2999

Custom Class Level Validation - Creating the Annotation

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

Upvotes: 1

Views: 97

Answers (1)

Amongalen
Amongalen

Reputation: 3131

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

Upvotes: 4

Related Questions