class ServiceConfigBean<T> extends ServiceConfig<T>
        implements
        BeanFactoryAware,
        InitializingBean,
        DisposableBean,
        ApplicationListener<ContextRefreshedEvent> {

    private static final long serialVersionUID = -7247592395983804440L;

    private transient BeanFactory beanFactory;

    @Override
    public void destroy() throws Exception {
        unexport();
    }

    @Override
    public void afterPropertiesSet() throws Exception {

        // 注意:basicConfig需要首先配置，因为其他可能会依赖于basicConfig的配置
        checkAndConfigBasicConfig();
        checkAndConfigExport();
        checkAndConfigRegistry();

        // 等spring初始化完毕后，再export服务
        // export();
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if (!getExported().get()) {
            export();
        }
    }

    /**
     * 检查并配置basicConfig
     */
    private void checkAndConfigBasicConfig() {
        if (getBasicService() == null) {
            if (MotanNamespaceHandler.basicServiceConfigDefineNames.size() == 0) {
                if (beanFactory instanceof ListableBeanFactory) {
                    ListableBeanFactory listableBeanFactory = (ListableBeanFactory) beanFactory;
                    String[] basicServiceConfigNames = listableBeanFactory.getBeanNamesForType
                            (BasicServiceInterfaceConfig
                                    .class);
                    MotanNamespaceHandler.basicServiceConfigDefineNames.addAll(Arrays.asList(basicServiceConfigNames));
                }
            }
            for (String name : MotanNamespaceHandler.basicServiceConfigDefineNames) {
                BasicServiceInterfaceConfig biConfig = beanFactory.getBean(name, BasicServiceInterfaceConfig.class);
                if (biConfig == null) {
                    continue;
                }
                if (MotanNamespaceHandler.basicServiceConfigDefineNames.size() == 1) {
                    setBasicService(biConfig);
                } else if (biConfig.isDefault() != null && biConfig.isDefault().booleanValue()) {
                    setBasicService(biConfig);
                }
            }
        }
    }

    /**
     * 检查是否已经装配export，如果没有则到basicConfig查找
     */
    private void checkAndConfigExport() {<FILL_FUNCTION_BODY>}

    /**
     * 检查并配置registry
     */
    private void checkAndConfigRegistry() {
        if (CollectionUtil.isEmpty(getRegistries()) && getBasicService() != null
                && !CollectionUtil.isEmpty(getBasicService().getRegistries())) {
            setRegistries(getBasicService().getRegistries());
        }
        if (CollectionUtil.isEmpty(getRegistries())) {
            for (String name : MotanNamespaceHandler.registryDefineNames) {
                RegistryConfig rc = beanFactory.getBean(name, RegistryConfig.class);
                if (rc == null) {
                    continue;
                }
                if (MotanNamespaceHandler.registryDefineNames.size() == 1) {
                    setRegistry(rc);
                } else if (rc.isDefault() != null && rc.isDefault().booleanValue()) {
                    setRegistry(rc);
                }
            }
        }
        if (CollectionUtil.isEmpty(getRegistries())) {
            setRegistry(MotanFrameworkUtil.getDefaultRegistryConfig());
        }
        for (RegistryConfig registryConfig : getRegistries()) {
            SpringBeanUtil.addRegistryParamBean(registryConfig, beanFactory);
        }
    }
}

        if (StringUtils.isBlank(getExport()) && getBasicService() != null
                && !StringUtils.isBlank(getBasicService().getExport())) {
            setExport(getBasicService().getExport());
            if (getBasicService().getProtocols() != null) {
                setProtocols(new ArrayList<ProtocolConfig>(getBasicService().getProtocols()));
            }
        }

        if (CollectionUtil.isEmpty(getProtocols()) && StringUtils.isNotEmpty(getExport())) {
            Map<String, Integer> exportMap = ConfigUtil.parseExport(export);
            if (!exportMap.isEmpty()) {
                List<ProtocolConfig> protos = new ArrayList<ProtocolConfig>();
                for (String p : exportMap.keySet()) {
                    ProtocolConfig proto = null;
                    try {
                        proto = beanFactory.getBean(p, ProtocolConfig.class);
                    } catch (NoSuchBeanDefinitionException e) {
                    }
                    if (proto == null) {
                        if (MotanConstants.PROTOCOL_MOTAN.equals(p)) {
                            proto = MotanFrameworkUtil.getDefaultProtocolConfig();
                        } else {
                            throw new MotanFrameworkException(String.format("cann't find %s ProtocolConfig bean! export:%s", p, export),
                                    MotanErrorMsgConstant.FRAMEWORK_INIT_ERROR);
                        }
                    }

                    protos.add(proto);
                }
                setProtocols(protos);
            }
        }
        if (StringUtils.isEmpty(getExport()) || CollectionUtil.isEmpty(getProtocols())) {
            throw new MotanFrameworkException(String.format("%s ServiceConfig must config right export value!", getInterface().getName()),
                    MotanErrorMsgConstant.FRAMEWORK_INIT_ERROR);
        }
    
<methods>public non-sealed void <init>() ,public synchronized void export() ,public com.weibo.api.motan.config.BasicServiceInterfaceConfig getBasicService() ,public static ConcurrentHashSet<java.lang.String> getExistingServices() ,public java.util.concurrent.atomic.AtomicBoolean getExported() ,public List<Exporter<T>> getExporters() ,public java.lang.String getHost() ,public Class<?> getInterface() ,public List<com.weibo.api.motan.config.MethodConfig> getMethods() ,public Map<java.lang.String,java.lang.Integer> getProtocolAndPort() ,public T getRef() ,public boolean hasMethods() ,public void setBasicService(com.weibo.api.motan.config.BasicServiceInterfaceConfig) ,public void setInterface(Class<T>) ,public void setMethods(com.weibo.api.motan.config.MethodConfig) ,public void setMethods(List<com.weibo.api.motan.config.MethodConfig>) ,public void setRef(T) ,public synchronized void unexport() <variables>private com.weibo.api.motan.config.BasicServiceInterfaceConfig basicService,private static final ConcurrentHashSet<java.lang.String> existingServices,private final java.util.concurrent.atomic.AtomicBoolean exported,private final List<Exporter<T>> exporters,private Class<T> interfaceClass,protected List<com.weibo.api.motan.config.MethodConfig> methods,private T ref,private static final long serialVersionUID