【发布时间】:2022-02-06 15:03:08
【问题描述】:
我的目标是创建类级别的注释,但我不断收到此错误。出于某种原因,当我使用 getClass 获取注释信息时,反射不起作用。我尝试使用方面,但我不确定如何使 spring boot 方面注释类级别。
org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.lang.Class.
以下是我使用的类
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Target(ElementType.TYPE)
public @interface ValidateInput {
short minLength();
short maxLength();
String regex() default "";
}
public abstract class SimpleValidation {
private String text;
private ValidateInput info = this.getClass().getAnnotation(ValidateInput.class);
protected SimpleValidation(String text) {
this.text = text;
}
}
@Value
@EqualsAndHashCode(callSuper = true)
@ValidateInput(maxLength = 50, minLength = 5, regex = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$")
public class Email extends SimpleValidation {
String email;
public Email(String email) {
super(email);
this.email = email;
}
}
【问题讨论】:
标签: java spring mongodb spring-boot