组件注册-@Import-使用ImportBeanDefinitionRegistrar

创建一个实现ImportBeanDefinitionRegistrar接口的类

@Configuration
@Import({Person.class, MyImportSelector.class, MyImportBeanDefinitionRegistrar.class})
public class MainConfig2
public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    /**
     *
     * @param importingClassMetadata 当前类的注解信息
     * @param registry BeanDefinition注册类,把所有需要添加到容器的bean通过registerBeanDefinition()手工注册进来
     */
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(RainBow.class);
        registry.registerBeanDefinition("rainBow", rootBeanDefinition);
    }

}
org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.annotation.internalCommonAnnotationProcessor
org.springframework.context.event.internalEventListenerProcessor
org.springframework.context.event.internalEventListenerFactory
mainConfig2
com.yyc.bean.Person
rainBow

 

posted on 2019-05-23 17:43  星辰钟塔的玛利亚女士  阅读(157)  评论(0编辑  收藏  举报

导航