如何将多个注释组合在一个注释中并重命名其属性



目的是将几个spring验证注释组合在一起,并重新粘贴它们的默认属性。举一个简单的例子:

class @interface A {
int value();
}
class @interface B {
int value();
}

我想做一些类似的事情:

class @interface Combo {
int a(); // have this directed to A.value
int b(); // have this directed to B.value
}

所以在使用中,它看起来像:

@Combo(a = 1, b = 2)

并具有的效果

@A(1)
@B(2)

据我所知,Java不支持合并注释,因为编译器不提供该功能。在spring中组合注释相当容易。例如:

class @interface A {
int value();
}
class @interface B {
int value();
}
@A
@B
class @interface Combo {
int a(); // have this directed to A.value
int b(); // have this directed to B.value
}

上面的代码将在spring上工作,这就是创建的spring引导注释的数量。例如,@SpringBootApplication主要是三个注释的组合:@ComponentScan, @EnableAutoConfiguration and @SpringBootConfiguration

最新更新