我可以使用 @AliasFor 来子类化注释吗?
我有一些要更改的注释:添加或更改默认值。注释不能分类,但是有[@aliasfor] [1]
的注释。我试图使用它。
我得到了
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface BaseAnnotation {
String target();
boolean redirect) default false;
}
,
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface DerivedAnnotation {
@AliasFor(annotation = BaseAnnotation.class, attribute = "target")
String target() default "";
@AliasFor(annotation = BaseAnnotation.class, attribute = "redirect")
boolean redirect() default true;
}
我想为target
参数添加默认值,然后更改redirect
参数的默认值。
然后我应用了注释,
@GetMapping("/v1/...")
@DerivedAnnotation
public void myEndpoint(...) {
但是失败了
org.springframework.beans.factory.beandefinitionstoreexception:失败 读取候选组件类:文件[/...controller.class];嵌套 例外是 org.springframework.core.annotation.annotationConfigurationException: @Aliasfor在注释中属性“重定向”声明 [...派生的Annotation]在 注释[... baseannotation]不是meta-present。
它是什么,可以做什么?
I have some annotation which I want to change: add or change default values. Annotation cannot be subclassed, but there is an annotation of [@AliasFor][1]
. I tried to use it.
I got
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface BaseAnnotation {
String target();
boolean redirect) default false;
}
and I made
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface DerivedAnnotation {
@AliasFor(annotation = BaseAnnotation.class, attribute = "target")
String target() default "";
@AliasFor(annotation = BaseAnnotation.class, attribute = "redirect")
boolean redirect() default true;
}
i.e. I wanted to add default value for target
parameter and change default value for redirect
parameter.
Then I have applied my annotation
@GetMapping("/v1/...")
@DerivedAnnotation
public void myEndpoint(...) {
but it is failing with error
org.springframework.beans.factory.BeanDefinitionStoreException: Failed
to read candidate component class: file [/...Controller.class]; nested
exception is
org.springframework.core.annotation.AnnotationConfigurationException:
@AliasFor declaration on attribute 'redirect' in annotation
[...DerivedAnnotation] declares an alias for attribute 'redirect' in
annotation [...BaseAnnotation] which is not meta-present.
What is it and what can be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论