Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How annotation internally works in java

I know how to create custom annotation. But i am unable to understand how does it work internally. If i take example of spring annontation.

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

if we see internal details of @PropertySource annotation

@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();
}

We do not have provided any implementation here for loading property file. Then How is it loading property file from classpath. Who is working behind the scene ?

like image 369
sachin thakur Avatar asked Mar 12 '26 11:03

sachin thakur


1 Answers

Really simple: framework. That is. All 'custom' annotations processed by frameworks using reflection. Only small scope of annotations are processed by compiler, such as @Override, @SuppressWarnings, @Retention and so on

like image 149
ZhenyaM Avatar answered Mar 15 '26 01:03

ZhenyaM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!