
Java 8 之前如何重复使用注解
在 Java 8 之前我们不能在一个类型重复使用同一个注解,例如 Spring 的注解 @PropertySource
不能下面那样来引入多个属性文件
@PropertySource("classpath:config.properties")
@PropertySource("file:application.properties")
public class MainApp {}
上面的代码无法在 Java 7 下通过编译,错误是: Duplicate annotation
于是我们在 Java 8 之前想到了一个方案来规避 Duplicate Annotation 的错误: 即声明一个新的 Annotation 来包裹 @PropertySource
, 如 @PropertySources
然后使用时两个注解齐上阵 阅读全文 >>