为什么 Spring 的 @Component 注释运行时?



我想知道为什么Spring的@ComponentAnnotation实现有RetentionPolicy.RUNTIME。以下是github 的官方实现

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

在我看来,所有用@Component注释的Spring组件的扫描将在编译时完成,所有结果(带注释的类(将以某种方式存储在ApplicationContext中。我想我错了,但为什么这个注释需要是RetentionPolicy.Runtime

组件扫描是在启动时完成的,而不是在编译时。此外,方面(AOP(是在运行时中创建的

最新更新