@AliasFor与@Retention(RetentionPolicy.METHOD)的接口?

时间:2018-03-27 01:53:38

标签: java spring annotations swagger

所以我试图为

创建一个别名
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ApiResponses {
    ApiResponse[] value();
}

我尝试了什么,

@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface targetTest {
    @AliasFor(annotation = ApiResponses.class, attribute="value")
    ApiResponse[] value()
    default {
        @ApiResponse(code = 200, message = "test1"),
        @ApiResponse(code = 400, message = "test2"),
        @ApiResponse(code = 404, message = "test3"),
        @ApiResponse(code = 500, message = "test4")
    };
}

当我使用

时,这不会覆盖ApiResponses注释
@targetTest
doSomething()

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您需要在@ApiResponses

上添加TargetTest
@Target({ANNOTATION_TYPE, METHOD})
@Retention(RUNTIME)
public @interface ApiResponses {
    ApiResponse[] value() default {};
}

@Target(METHOD)
@Retention(RUNTIME)
@ApiResponses
public @interface TargetTest {
    @AliasFor(annotation = ApiResponses.class)
    ApiResponse[] value() default {...};
}