注释如何在java中内部工作

时间:2017-09-19 18:19:13

标签: java annotations

我知道如何创建自定义注释。但我无法理解它是如何在内部工作的。如果我以春天的方式为例。

@PropertySource(value = { "classpath:database.properties" }). 

如果我们看到@PropertySource注释的内部细节

@Target({ java.lang.annotation.ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Repeatable(PropertySources.class)
public @interface PropertySource {
    public abstract String name();

    public abstract String[] value();

    public abstract boolean ignoreResourceNotFound();
}

我们这里没有为加载属性文件提供任何实现。 然后如何从classpath加载属性文件。谁在幕后工作?

1 个答案:

答案 0 :(得分:1)

非常简单:框架。那是。所有' custom'框架使用反射处理的注释。编译器只处理小范围的注释,例如@Override@SuppressWarnings@Retention等等