【发布时间】:2016-08-08 11:53:18
【问题描述】:
我正在尝试使用 spring 的 Meta-annotation 使用 aliasFor 注释来为 springs RequestParam
创建自定义注释只需“扩展/替换”
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface RequestParam {
@AliasFor("name")
String value() default "";
----
}
加上我的注释
@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;
}
这样会抛出异常
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.
问题是,如果没有在 QueryParam 上注释的 RequestParam,这是行不通的。并且不可能将 RequestParam 作为它的 PARAMETER 目标。
@RequestParam <--This is not possible.
public @interface QueryParam
那么还有其他方法可以实现吗?
【问题讨论】:
标签: java spring spring-mvc spring-boot spring-annotations