Home > front end >  Why is Spring's @Component Annotation RUNTIME?
Why is Spring's @Component Annotation RUNTIME?

Time:09-08

I am wondering, why Spring's implementation of the @Component Annotation has RetentionPolicy.RUNTIME. Here's the official implementation from github

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Indexed
public @interface Component {
    String value() default "";
}

In my thought, the scanning for all Spring-Components annotated with @Component would be done at compile-time and all the results (annotated classes) would somehow be stored inside the ApplicationContext. I guess I am wrong, but why does this annotation need to be RetentionPolicy.Runtime?

CodePudding user response:

The component scanning is done at the startup, not at the compilation. Also, the aspects (AOP) are created at the runtime

  • Related