AnnotationConfigApplicationContext
内部使用了AnnotatedBeanDefinitionReader;ClassPathBeanDefinitionScanner
/** 使用AnnotatedBeanDefinitionReader读取配置类*/ public void register(Class<?>... annotatedClasses) { Assert.notEmpty(annotatedClasses, "At least one annotated class must be specified"); this.reader.register(annotatedClasses); } /** 使用ClassPathBeanDefinitionScanner扫描指定包*/ public void scan(String... basePackages) { Assert.notEmpty(basePackages, "At least one base package must be specified"); this.scanner.scan(basePackages); } /** 使用AnnotatedBeanDefinitionReader注册一个bean,使用指定的构造函数。*/ public <T> void registerBean(Class<T> annotatedClass, Object... constructorArguments) { registerBean(null, annotatedClass, constructorArguments); } public <T> void registerBean(@Nullable String beanName, Class<T> annotatedClass, Object... constructorArguments) { this.reader.doRegisterBean(annotatedClass, null, beanName, null, bd -> { for (Object arg : constructorArguments) { bd.getConstructorArgumentValues().addGenericArgumentValue(arg); } }); } @Override public <T> void registerBean(@Nullable String beanName, Class<T> beanClass, @Nullable Supplier<T> supplier, BeanDefinitionCustomizer... customizers) { this.reader.doRegisterBean(beanClass, supplier, beanName, null, customizers); }
AnnotatedBeanDefinitionReader