Issue
I am wondering, why Spring's implementation of the @Component
Annotation has RetentionPolicy.RUNTIME
.
Here's the official implementation from href="https://github.com/spring-projects/spring-framework/blob/main/spring-context/src/main/java/org/springframework/stereotype/Component.java" rel="nofollow noreferrer">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
?
Solution
The component scanning is done at the startup, not at the compilation. Also, the aspects (AOP) are created at the runtime
Answered By - Oreste Viron
Answer Checked By - Marie Seifert (JavaFixing Admin)