Disconf源码分析01

DisconfMgrBean.java

 

由UML类图,DisconfMgrBean实现了BeanDefinitionRegistryPostProcessor接口的postProcessBeanDefinitionRegistry方法,该方法允许在bean实例化之前允许我们注册新的BeanDefinition,代码逻辑如下:

DisconfMgrBean.postProcessBeanDefinitionRegistry

@Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {

        // 为了做兼容
        DisconfCenterHostFilesStore.getInstance().addJustHostFileSet(fileList);
        //配置的被扫描的包
        List scanPackList = StringUtil.parseStringToStringList(scanPackage, SCAN_SPLIT_TOKEN);
        // unique
        Set hs = new HashSet();
        hs.addAll(scanPackList);
        scanPackList.clear();
        scanPackList.addAll(hs);

        // 进行扫描
        DisconfMgr.getInstance().setApplicationContext(applicationContext);
        DisconfMgr.getInstance().firstScan(scanPackList);

        // 注册DisconfAspectJ
        registerAspect(registry);
    }

     private void registerAspect(BeanDefinitionRegistry registry) {

        GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
        beanDefinition.setBeanClass(DisconfAspectJ.class);
        beanDefinition.setLazyInit(false);
        beanDefinition.setAbstract(false);
        beanDefinition.setAutowireCandidate(true);
        beanDefinition.setScope("singleton");

        registry.registerBeanDefinition("disconfAspectJ", beanDefinition);
    }

配置的扫包去重,设置DisconfMgr的applicationContext属性并进行第一次扫描,注册DisconfAspectJ类的beanDefinition到Spring容器,DisconfAspectJ主要是对我们加了@DisconfFileItem和@DisconfFile配置的Bean的get/is方法进行切面。

 

 

你可能感兴趣的:(disconf源码)