我正在尝试使用aliasFor批注使用spring的Meta批注为springs RequestParam创建自定义批注
只需“扩展/替换”
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface RequestParam {
@AliasFor("name")
String value() default "";
----
}
Run Code Online (Sandbox Code Playgroud)
加上我的注释
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface QueryParam {
@AliasFor(annotation = RequestParam.class, attribute = "name")
String name() default "";
@AliasFor(annotation = RequestParam.class, attribute = "required")
boolean required() default false;
@AliasFor(annotation = RequestParam.class, attribute = "defaultValue")
String defaultValue() default ValueConstants.DEFAULT_NONE;
}
Run Code Online (Sandbox Code Playgroud)
这样就抛出了异常
org.springframework.core.annotation.AnnotationConfigurationException: @AliasFor declaration on attribute [name] in annotation [package.QueryParam] declares an alias for attribute [name] in meta-annotation [org.springframework.web.bind.annotation.RequestParam] which is not meta-present. …Run Code Online (Sandbox Code Playgroud)