Java 类org.springframework.beans.factory.support.BeanDefinitionRegistry 实例源码

项目:mybatisplus-boot-starter    文件:MybatisPlusAutoConfiguration.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

    logger.debug("Searching for mappers annotated with @Mapper");

    ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);

    try {
        if (this.resourceLoader != null) {
            scanner.setResourceLoader(this.resourceLoader);
        }

        List<String> packages = AutoConfigurationPackages.get(this.beanFactory);
        if (logger.isDebugEnabled()) {
            for (String pkg : packages) {
                logger.debug("Using auto-configuration base package '" + pkg + "'");
            }
        }

        scanner.setAnnotationClass(Mapper.class);
        scanner.registerFilters();
        scanner.doScan(StringUtils.toStringArray(packages));
    } catch (IllegalStateException ex) {
        logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled." + ex);
    }
}
项目:holon-datastore-jpa    文件:JpaRegistrar.java   
/**
 * Get the {@link DataSource} type bean name which corresponds to given data context id
 * @param registry Bean registry
 * @param beanFactory Bean factory
 * @param dataContextId Optional data context id
 * @return The DataSource bean name, or <code>null</code> if not found
 */
private static String getDataSourceBeanName(BeanDefinitionRegistry registry, BeanFactory beanFactory,
        String dataContextId) {
    // check unique DataSource if no data context id specified
    if (dataContextId == null && beanFactory instanceof ListableBeanFactory) {
        String[] dataSourceBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
                (ListableBeanFactory) beanFactory, DataSource.class, false, false);
        if (dataSourceBeanNames != null && dataSourceBeanNames.length == 1) {
            return dataSourceBeanNames[0];
        }
    }
    // check bean name using data context id
    String dsBeanName = BeanRegistryUtils.buildBeanName(dataContextId,
            EnableDataSource.DEFAULT_DATASOURCE_BEAN_NAME);
    if (registry.containsBeanDefinition(dsBeanName) && beanFactory.isTypeMatch(dsBeanName, DataSource.class)) {
        return dsBeanName;
    }
    return null;
}
项目:apollo-custom    文件:ApolloConfigRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
  AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata
      .getAnnotationAttributes(EnableApolloConfig.class.getName()));
  String[] namespaces = attributes.getStringArray("value");
  int order = attributes.getNumber("order");
  PropertySourcesProcessor.addNamespaces(Lists.newArrayList(namespaces), order);

  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesPlaceholderConfigurer.class.getName(),
      PropertySourcesPlaceholderConfigurer.class);

  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesProcessor.class.getName(),
      PropertySourcesProcessor.class);

  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, ApolloAnnotationProcessor.class.getName(),
      ApolloAnnotationProcessor.class);
}
项目:lams    文件:AopConfigUtils.java   
private static BeanDefinition registerOrEscalateApcAsRequired(Class<?> cls, BeanDefinitionRegistry registry, Object source) {
    Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
    if (registry.containsBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME)) {
        BeanDefinition apcDefinition = registry.getBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME);
        if (!cls.getName().equals(apcDefinition.getBeanClassName())) {
            int currentPriority = findPriorityForClass(apcDefinition.getBeanClassName());
            int requiredPriority = findPriorityForClass(cls);
            if (currentPriority < requiredPriority) {
                apcDefinition.setBeanClassName(cls.getName());
            }
        }
        return null;
    }
    RootBeanDefinition beanDefinition = new RootBeanDefinition(cls);
    beanDefinition.setSource(source);
    beanDefinition.getPropertyValues().add("order", Ordered.HIGHEST_PRECEDENCE);
    beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    registry.registerBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME, beanDefinition);
    return beanDefinition;
}
项目:holon-core    文件:BeanFactoryScopeRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {

    Map<String, Object> attributes = annotationMetadata.getAnnotationAttributes(EnableBeanContext.class.getName());
    if (attributes == null) {
        return;
    }

    boolean lookupByType = (boolean) attributes.get("lookupByType");

    // check environment
    if (environment.containsProperty(EnableBeanContext.LOOKUP_BY_TYPE_PROPERTY_NAME)) {
        lookupByType = environment.getProperty(EnableBeanContext.LOOKUP_BY_TYPE_PROPERTY_NAME, Boolean.class);
    }

    // register post processor
    if (!registry.containsBeanDefinition(BEAN_FACTORY_SCOPE_POST_PROCESSOR_NAME)) {
        BeanDefinitionBuilder postProcessorBuilder = BeanDefinitionBuilder
                .genericBeanDefinition(BeanFactoryScopePostProcessor.class).setDestroyMethodName("unregister")
                .addPropertyValue("lookupByType", lookupByType).setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        registry.registerBeanDefinition(BEAN_FACTORY_SCOPE_POST_PROCESSOR_NAME,
                postProcessorBuilder.getBeanDefinition());
    }
}
项目:configx    文件:EnableConfigServiceImportSelector.java   
@Override
        public void registerBeanDefinitions(AnnotationMetadata metadata,
                                            BeanDefinitionRegistry registry) {
            MultiValueMap<String, Object> attributes = metadata
                    .getAllAnnotationAttributes(
                            EnableConfigService.class.getName(), false);
            Object[] type = attributes == null ? null
                    : (Object[]) attributes.getFirst("converters");
            if (type == null || type.length == 0) {
                return;
            }

            List<Class<?>> types = collectClasses(attributes.get("converters"));
//            for (Class<?> type : types) {
//                String name = type.getName();
//                if (!registry.containsBeanDefinition(name)) {
//                    registerBeanDefinition(registry, type, name);
//                }
//            }

            registerConverters(registry, types);
        }
项目:apollo-custom    文件:BeanRegistrationUtil.java   
public static boolean registerBeanDefinitionIfNotExists(BeanDefinitionRegistry registry, String beanName,
                                                        Class<?> beanClass) {
  if (registry.containsBeanDefinition(beanName)) {
    return false;
  }

  String[] candidates = registry.getBeanDefinitionNames();

  for (String candidate : candidates) {
    BeanDefinition beanDefinition = registry.getBeanDefinition(candidate);
    if (Objects.equals(beanDefinition.getBeanClassName(), beanClass.getName())) {
      return false;
    }
  }

  BeanDefinition annotationProcessor = BeanDefinitionBuilder.genericBeanDefinition(beanClass).getBeanDefinition();
  registry.registerBeanDefinition(beanName, annotationProcessor);

  return true;
}
项目:EatDubbo    文件:AnnotationBean.java   
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
        throws BeansException {
    if (annotationPackage == null || annotationPackage.length() == 0) {
        return;
    }
    if (beanFactory instanceof BeanDefinitionRegistry) {
        try {
            // init scanner
            Class<?> scannerClass = ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
            Object scanner = scannerClass.getConstructor(new Class<?>[] {BeanDefinitionRegistry.class, boolean.class}).newInstance(new Object[] {(BeanDefinitionRegistry) beanFactory, true});
            // add filter
            Class<?> filterClass = ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
            Object filter = filterClass.getConstructor(Class.class).newInstance(Service.class);
            Method addIncludeFilter = scannerClass.getMethod("addIncludeFilter", ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
            addIncludeFilter.invoke(scanner, filter);
            // scan packages
            String[] packages = Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
            Method scan = scannerClass.getMethod("scan", new Class<?>[]{String[].class});
            scan.invoke(scanner, new Object[] {packages});
        } catch (Throwable e) {
            // spring 2.0
        }
    }
}
项目:holon-jdbc    文件:DataSourcesTransactionManagerAutoConfigurationRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

    if (beanFactory instanceof ListableBeanFactory) {

        String[] dataSourceBeanNames = ((ListableBeanFactory) beanFactory).getBeanNamesForType(DataSource.class,
                false, true);
        if (dataSourceBeanNames != null) {
            for (String dataSourceBeanName : dataSourceBeanNames) {
                BeanDefinition bd = registry.getBeanDefinition(dataSourceBeanName);
                if (bd instanceof DataContextBoundBeanDefinition) {
                    DataSourceRegistrar.registerDataSourceTransactionManager(registry, dataSourceBeanName,
                            ((DataContextBoundBeanDefinition) bd).getDataContextId().orElse(null),
                            PrimaryMode.AUTO);
                }
            }
        }

    }

}
项目:disconf-client-ext    文件:DisconfMgrBeanExt.java   
/**
 * 第一次扫描<br/>
 * 在Spring内部的Bean定义初始化后执行,这样是最高优先级的
 */
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {

    // 为了做兼容
    DisconfCenterHostFilesStore.getInstance().addJustHostFileSet(fileList);

    List<String> scanPackList = StringUtil.parseStringToStringList(scanPackage, SCAN_SPLIT_TOKEN);
    // unique
    Set<String> hs = new HashSet<String>();
    hs.addAll(scanPackList);
    scanPackList.clear();
    scanPackList.addAll(hs);

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

    // register java bean
    registerAspect(registry);
}
项目:embedded-database-spring-test    文件:EmbeddedPostgresContextCustomizerFactory.java   
@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
    Class<?> testClass = mergedConfig.getTestClass();
    FlywayTest flywayAnnotation = AnnotatedElementUtils.findMergedAnnotation(testClass, FlywayTest.class);

    BeanDefinitionRegistry registry = getBeanDefinitionRegistry(context);
    RootBeanDefinition registrarDefinition = new RootBeanDefinition();

    registrarDefinition.setBeanClass(PreloadableEmbeddedPostgresRegistrar.class);
    registrarDefinition.getConstructorArgumentValues()
            .addIndexedArgumentValue(0, databaseAnnotation);
    registrarDefinition.getConstructorArgumentValues()
            .addIndexedArgumentValue(1, flywayAnnotation);

    registry.registerBeanDefinition("preloadableEmbeddedPostgresRegistrar", registrarDefinition);
}
项目:parabuild-ci    文件:DwrNamespaceHandler.java   
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext)
{
    Element element = (Element) node;
    String type = element.getAttribute("type");
    String className = element.getAttribute("class");
    String javascriptClassName = element.getAttribute("javascript");

    BeanDefinitionRegistry registry = parserContext.getRegistry();

    ConverterConfig converterConfig = new ConverterConfig();
    converterConfig.setType(type);
    converterConfig.setJavascriptClassName(javascriptClassName);
    parseConverterSettings(converterConfig, element);
    lookupConverters(registry).put(className, converterConfig);

    return definition;
}
项目:jkami    文件:MapperScannerConfigurer.java   
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
    /**
     * 注册通用Dao
     */
    registerBaseCommonDao(registry);
    /**
     * 注册代理类
     */
    registerProxyHandler(registry);
    /**
     * 加载其他层接口
     */
    ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry, annotation);
    scanner.scan(StringUtils.tokenizeToStringArray(this.basePackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS));
}
项目:mapper-boot-starter    文件:MapperAutoConfiguration.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

    logger.debug("Searching for mappers annotated with @Mapper");

    ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);
    scanner.setMapperProperties(environment);
    try {
        if (this.resourceLoader != null) {
            scanner.setResourceLoader(this.resourceLoader);
        }

        List<String> packages = AutoConfigurationPackages.get(this.beanFactory);
        if (logger.isDebugEnabled()) {
            for (String pkg : packages) {
                logger.debug("Using auto-configuration base package '{}'", pkg);
            }
        }

        scanner.setAnnotationClass(Mapper.class);
        scanner.registerFilters();
        scanner.doScan(StringUtils.toStringArray(packages));
    } catch (IllegalStateException ex) {
        logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled.", ex);
    }
}
项目:albedo-thrift    文件:ServiceStarter.java   
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    BeanDefinitionRegistry registry=(BeanDefinitionRegistry)beanFactory;
    CuratorFramework curatorFramework = beanFactory.getBean(CuratorFramework.class);
    ServiceRouter serviceRouter = beanFactory.getBean(ServiceRouter.class);
    for(Class clazz:list){
        GenericBeanDefinition definition=(GenericBeanDefinition) BeanDefinitionBuilder.genericBeanDefinition(clazz).getBeanDefinition();
        definition.getPropertyValues().addPropertyValue("innerClass",clazz);
        definition.getPropertyValues().addPropertyValue("factory",beanFactory);
        ServiceApi serviceApi = map.get(clazz.getName());
        definition.getPropertyValues().addPropertyValue("proccessName",serviceApi.getName());

        String path = "/"+clazz.getName()+"/"+ (serviceApi!=null ? serviceApi.getVersion() :
                ThriftConstant.DEFAULT_VERSION);
        ServiceDiscover serviceDiscover = new ZookeeperServiceDiscover(curatorFramework, path);

        definition.getPropertyValues().addPropertyValue("serverManager",
                new ServerManager(serviceDiscover, serviceRouter));

        definition.setBeanClass(ProxyFactoryBean.class);
        definition.setDestroyMethodName("close");
        registry.registerBeanDefinition(clazz.getName(), definition);
    }

}
项目:gemini.blueprint    文件:ParsingUtils.java   
/**
 * Generates a Blueprint specific bean name.
 * 
 * @param definition
 * @param registry
 * @param isInnerBean
 * @return
 * @throws BeanDefinitionStoreException
 */
public static String generateBlueprintBeanName(BeanDefinition definition, BeanDefinitionRegistry registry,
        boolean isInnerBean) throws BeanDefinitionStoreException {

    String initialName =
            BLUEPRINT_GENERATED_NAME_PREFIX
                    + BeanDefinitionReaderUtils.generateBeanName(definition, registry, isInnerBean);

    String generatedName = initialName;
    int counter = 0;
    while (registry.containsBeanDefinition(generatedName)) {
        generatedName = initialName + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR + counter;
        counter++;
    }

    return generatedName;
}
项目:loc-framework    文件:LocMybatisAutoConfiguration.java   
private void createClassPathMapperScanner(BeanDefinitionRegistry registry, String prefixName) {
  ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry);

  try {
    if (this.resourceLoader != null) {
      scanner.setResourceLoader(this.resourceLoader);
    }

    List<String> packages = AutoConfigurationPackages.get(beanFactory);
    packages.forEach(pkg -> log.info("Using auto-configuration base package '{}'", pkg));

    scanner.setAnnotationClass(Mapper.class);
    scanner.setSqlSessionFactoryBeanName(prefixName + "SessionFactory");
    scanner.registerFilters();
    scanner.doScan(StringUtils.toStringArray(packages));
  } catch (IllegalStateException ex) {
    log.info("Could not determine auto-configuration package", ex);
  }
}
项目:lams    文件:ConfigurationClassPostProcessor.java   
/**
 * Prepare the Configuration classes for servicing bean requests at runtime
 * by replacing them with CGLIB-enhanced subclasses.
 */
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
    int factoryId = System.identityHashCode(beanFactory);
    if (this.factoriesPostProcessed.contains(factoryId)) {
        throw new IllegalStateException(
                "postProcessBeanFactory already called for this post-processor against " + beanFactory);
    }
    this.factoriesPostProcessed.add(factoryId);
    if (!this.registriesPostProcessed.contains(factoryId)) {
        // BeanDefinitionRegistryPostProcessor hook apparently not supported...
        // Simply call processConfigurationClasses lazily at this point then.
        processConfigBeanDefinitions((BeanDefinitionRegistry) beanFactory);
    }
    enhanceConfigurationClasses(beanFactory);
}
项目:dubbocloud    文件:AnnotationBean.java   
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
        throws BeansException {
    if (annotationPackage == null || annotationPackage.length() == 0) {
        return;
    }
    if (beanFactory instanceof BeanDefinitionRegistry) {
        try {
            // init scanner
            Class<?> scannerClass = ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
            Object scanner = scannerClass.getConstructor(new Class<?>[] {BeanDefinitionRegistry.class, boolean.class}).newInstance(new Object[] {(BeanDefinitionRegistry) beanFactory, true});
            // add filter
            Class<?> filterClass = ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
            Object filter = filterClass.getConstructor(Class.class).newInstance(Service.class);
            Method addIncludeFilter = scannerClass.getMethod("addIncludeFilter", ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
            addIncludeFilter.invoke(scanner, filter);
            // scan packages
            String[] packages = Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
            Method scan = scannerClass.getMethod("scan", new Class<?>[]{String[].class});
            scan.invoke(scanner, new Object[] {packages});
        } catch (Throwable e) {
            // spring 2.0
        }
    }
}
项目:holon-jdbc    文件:DataSourceRegistrar.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {

    if (!annotationMetadata.isAnnotated(EnableDataSource.class.getName())) {
        // ignore call from sub classes
        return;
    }

    Map<String, Object> attributes = annotationMetadata.getAnnotationAttributes(EnableDataSource.class.getName());

    // Annotation values
    String dataContextId = BeanRegistryUtils.getAnnotationValue(attributes, "dataContextId", null);
    PrimaryMode primaryMode = BeanRegistryUtils.getAnnotationValue(attributes, "primary", PrimaryMode.AUTO);
    boolean registerTransactionManager = BeanRegistryUtils.getAnnotationValue(attributes,
            "enableTransactionManager", false);

    String dsBeanName = registerDataSource(getEnvironment(), registry, dataContextId, primaryMode);

    // Transaction manager

    if (registerTransactionManager) {
        registerDataSourceTransactionManager(registry, dsBeanName, dataContextId, primaryMode);
    }

}
项目:jspider    文件:FieldDefineBeanDefinitionParser.java   
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    FieldDefine fieldDefine = parseFieldDefine(element);
    String id = fieldDefine.getId();
    if (StringUtils.isEmpty(id)) {
        id = fieldDefine.toString()+"-"+System.currentTimeMillis();
    }

    RootBeanDefinition beanDefinition = new RootBeanDefinition();
    beanDefinition.setBeanClass(FieldDefine.class);
    beanDefinition.setLazyInit(false);

    BeanDefinitionRegistry registry = parserContext.getRegistry();
    if (registry.containsBeanDefinition(id)) {
        throw new IllegalStateException("Duplicate spring bean id " + id);
    }
    registry.registerBeanDefinition(id, beanDefinition);

    MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
    propertyValues.addPropertyValue("id", id);
    propertyValues.addPropertyValue("name", fieldDefine.getName());
    propertyValues.addPropertyValue("type", fieldDefine.getType());
    propertyValues.addPropertyValue("selector", fieldDefine.getSelector());
    propertyValues.addPropertyValue("processor", fieldDefine.getProcessor());
    propertyValues.addPropertyValue("defines", fieldDefine.getDefines());

    return beanDefinition;
}
项目:configx    文件:ConfigBeanConfigUtils.java   
/**
 * 注册ConfigBeanPropertyResolver
 *
 * @param registry
 */
public static void registerConfigBeanPropertyResolver(BeanDefinitionRegistry registry) {
    if (!registry.containsBeanDefinition(CONFIG_BEAN_PROPERTY_RESOLVER_BEAN_NAME)) {
        BeanDefinitionBuilder bean = BeanDefinitionBuilder.genericBeanDefinition(ConfigPropertyResolver.class);
        registry.registerBeanDefinition(CONFIG_BEAN_PROPERTY_RESOLVER_BEAN_NAME, bean.getBeanDefinition());
    }
}
项目:configx    文件:ConfigBeanConfigUtils.java   
/**
 * 注册ConfigBeanConversionService
 *
 * @param registry
 */
public static void registerConfigBeanConversionService(BeanDefinitionRegistry registry) {
    if (!registry.containsBeanDefinition(CONFIG_BEAN_CONVERSION_SERVICE_BEAN_NAME)) {
        BeanDefinitionBuilder bean = BeanDefinitionBuilder.genericBeanDefinition(ConfigBeanConversionService.class);
        registry.registerBeanDefinition(CONFIG_BEAN_CONVERSION_SERVICE_BEAN_NAME, bean.getBeanDefinition());
    }
}
项目:lams    文件:PostProcessorRegistrationDelegate.java   
/**
 * Invoke the given BeanDefinitionRegistryPostProcessor beans.
 */
private static void invokeBeanDefinitionRegistryPostProcessors(
        Collection<? extends BeanDefinitionRegistryPostProcessor> postProcessors, BeanDefinitionRegistry registry) {

    for (BeanDefinitionRegistryPostProcessor postProcessor : postProcessors) {
        postProcessor.postProcessBeanDefinitionRegistry(registry);
    }
}
项目:springmock    文件:DoubleDefinitionsRegistrationContext.java   
private void registerBeanDefinition(DoubleDefinition doubleDefinition, String definitionName, BeanDefinitionRegistry beanDefinitionRegistry, BeanDefinition beanDefinition) {
    beanDefinitionRegistry.registerBeanDefinition(definitionName, beanDefinition);
    doubleDefinition.getAliases().forEach(alias -> beanDefinitionRegistry.registerAlias(definitionName, alias));
    if(!definitionName.equals(doubleDefinition.getName())) {
        beanDefinitionRegistry.registerAlias(definitionName, doubleDefinition.getName());
    }

    doublesRegisteredInContext.add(doubleDefinition);
}
项目:springboot-analysis    文件:MyBeanFactoryPostProcessor.java   
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    System.out.println("------ register custom bean in BeanFactoryPostProcessor");
    beanFactory.registerSingleton("createByBeanFactoryPostProcessor", new SimpleBeanInBeanFactoryPostProcessor());
    if(beanFactory instanceof BeanDefinitionRegistry) {
        BeanDefinitionReaderUtils.registerBeanDefinition(
                new BeanDefinitionHolder(new AnnotatedGenericBeanDefinition(SimpleBeanWithDefinitionInBeanFactoryPostProcessor.class), "simpleBeanWithDefinitionInBeanFactoryPostProcessor"),                             (BeanDefinitionRegistry) beanFactory
        );
    }
}
项目:configx    文件:EnableConfigServiceImportSelector.java   
private void registerConverters(BeanDefinitionRegistry registry, List<Class<?>> types) {

            // Register ConfigConverter by CustomConverterConfigurer
            String name = ConfigBeanConverterConfigurer.class.getName() + "." + EnableConfigService.class.getSimpleName();
            // converters
            List<ConfigBeanConverter> converters = instantiateConverters(types);

            BeanDefinitionBuilder builder = BeanDefinitionBuilder
                    .genericBeanDefinition(ConfigBeanConverterConfigurer.class);
            builder.addPropertyValue("converters", converters);
            AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();

            registry.registerBeanDefinition(name, beanDefinition);
        }
项目:configx    文件:DependencyConfigUtils.java   
public static void registerDependency(BeanDefinitionRegistry registry, String beanName, String[] propertyNames) {
    if (ArrayUtils.isEmpty(propertyNames)) {
        return;
    }
    String dependencyBeanName = beanName + ".dependency";
    BeanDefinitionBuilder meta = BeanDefinitionBuilder.genericBeanDefinition(RefreshBeanDependencyFactoryBean.class);
    meta.addPropertyValue("beanName", beanName);
    meta.addPropertyValue("propertyNames", propertyNames);
    registry.registerBeanDefinition(dependencyBeanName, meta.getBeanDefinition());
}
项目:keti    文件:GraphBeanDefinitionRegistryPostProcessor.java   
@Override
public void postProcessBeanDefinitionRegistry(final BeanDefinitionRegistry registry) {
    BeanDefinition resourceRepositoryBeanDefinition = new RootBeanDefinition(GraphResourceRepository.class);
    registry.registerBeanDefinition("resourceHierarchicalRepository", resourceRepositoryBeanDefinition);

    BeanDefinition subjectRepositoryBeanDefinition = new RootBeanDefinition(GraphSubjectRepository.class);
    registry.registerBeanDefinition("subjectHierarchicalRepository", subjectRepositoryBeanDefinition);
}
项目:xq_seckill_microservice    文件:DynamicDataSourceRegister.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("动态数据源注册开始>>>");
    }

    // 添加主数据源
    targetDataSources.put("master", DynamicDataSourceHolder.getMasterDS());
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("提供可选取Master数据源:{}", "master");
    }

    // 添加从数据源
    targetDataSources.putAll(DynamicDataSourceHolder.getSlaveDSMap());
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("提供可选取Slave数据源:{}", DynamicDataSourceHolder.getSlaveDSMap().keySet());
    }
    for (String key : DynamicDataSourceHolder.getSlaveDSMap().keySet()) {
        DynamicDataSourceHolder.getSlaveDSKeys().add(key);
    }

    // 创建DynamicDataSource
    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(DynamicDataSource.class);
    beanDefinition.setSynthetic(true);

    MutablePropertyValues mpv = beanDefinition.getPropertyValues();
    mpv.addPropertyValue("defaultTargetDataSource", DynamicDataSourceHolder.getMasterDS());
    mpv.addPropertyValue("targetDataSources", targetDataSources);

    registry.registerBeanDefinition("dataSource", beanDefinition);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("<<<动态数据源注册结束");
    }
}
项目:apollo-custom    文件:ConfigPropertySourcesProcessor.java   
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesPlaceholderConfigurer.class.getName(),
      PropertySourcesPlaceholderConfigurer.class);
  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, ApolloAnnotationProcessor.class.getName(),
      ApolloAnnotationProcessor.class);
}
项目:springmock    文件:ProblemWithObjectReturningFactoryMethodFailingTest.java   
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    final BeanDefinitionRegistry definitionRegistry = (BeanDefinitionRegistry) beanFactory;

    definitionRegistry.registerBeanDefinition("service", BeanDefinitionBuilder
            .rootBeanDefinition(Service.class)
            .setFactoryMethodOnBean("createService", "service2FactoryMethod")
            .getBeanDefinition());
}
项目:druid-spring-boot    文件:DruidDataSourceConfiguration.java   
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
    resolver.getSubProperties(EMPTY).keySet().stream()
            .map(key -> key.substring(0, key.indexOf(POINT)))
            .distinct()
            .forEach(dataSourceName -> {
                // 注册 BeanDefinition
                String camelName = CharMatcher.separatedToCamel().apply(dataSourceName);
                registry.registerBeanDefinition(camelName, genericDruidBeanDefinition());
                // 注册以 DataSource 为后缀的别名
                if (!camelName.toLowerCase().endsWith(BEAN_SUFFIX.toLowerCase())) {
                    registry.registerAlias(camelName, camelName + BEAN_SUFFIX);
                }
            });
}
项目:-artemis-disruptor-miaosha    文件:BeanRegisterUtils.java   
public static void registerSingleton(BeanDefinitionRegistry registry, String beanName, Object singletonObject) {

    if (!SingletonBeanRegistry.class.isAssignableFrom(registry.getClass())) {
      throw new IllegalArgumentException(
          "BeanDefinitionRegistry: " + registry.getClass().toString()
              + " doesn't implements SingletonBeanRegistry, cannot register JMS connection at runtime");
    }

    SingletonBeanRegistry beanDefinitionRegistry = (SingletonBeanRegistry) registry;
    beanDefinitionRegistry.registerSingleton(beanName, singletonObject);

  }
项目:hekate    文件:HekateRpcServiceConfigurer.java   
@Override
protected void registerBeans(InjectRpcClient annotation, ResolvableType targetType, BeanDefinitionRegistry registry) {
    String tag = annotation.tag().isEmpty() ? "" : '#' + annotation.tag();

    String name = RpcClientBean.class.getName() + tag + "-" + targetType.toString();

    if (!registry.containsBeanDefinition(name)) {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(RpcClientBean.class)
            .setLazyInit(true)
            .addPropertyValue("rpcInterface", targetType.getType().getTypeName());

        if (!annotation.tag().isEmpty()) {
            builder.addPropertyValue("tag", annotation.tag());
        }

        AbstractBeanDefinition def = builder.getBeanDefinition();

        AutowireCandidateQualifier qualifier = new AutowireCandidateQualifier(annotation.annotationType());

        if (!annotation.tag().isEmpty()) {
            qualifier.setAttribute("tag", annotation.tag());
        }

        def.addQualifier(qualifier);

        registry.registerBeanDefinition(name, def);
    }
}
项目:lams    文件:AnnotationBeanNameGenerator.java   
@Override
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
    if (definition instanceof AnnotatedBeanDefinition) {
        String beanName = determineBeanNameFromAnnotation((AnnotatedBeanDefinition) definition);
        if (StringUtils.hasText(beanName)) {
            // Explicit bean name found.
            return beanName;
        }
    }
    // Fallback: generate a unique default bean name.
    return buildDefaultBeanName(definition, registry);
}
项目:hekate    文件:HekateLocalMetricsServiceConfigurer.java   
@Override
protected void registerBeans(InjectCounter annotation, ResolvableType targetType, BeanDefinitionRegistry registry) {
    String name = CounterMetricBean.class.getName() + "-" + annotation.value();

    if (!registry.containsBeanDefinition(name)) {
        AbstractBeanDefinition def = BeanDefinitionBuilder.rootBeanDefinition(CounterMetricBean.class)
            .setLazyInit(true)
            .addPropertyValue("name", annotation.value())
            .getBeanDefinition();

        def.addQualifier(new AutowireCandidateQualifier(annotation.annotationType(), annotation.value()));

        registry.registerBeanDefinition(name, def);
    }
}
项目:hekate    文件:HekateLocalMetricsServiceConfigurer.java   
@Override
protected void registerBeans(InjectMetric annotation, ResolvableType targetType, BeanDefinitionRegistry registry) {
    String name = MetricBean.class.getName() + "-" + annotation.value();

    if (!registry.containsBeanDefinition(name)) {
        AbstractBeanDefinition def = BeanDefinitionBuilder.rootBeanDefinition(MetricBean.class)
            .setLazyInit(true)
            .addPropertyValue("name", annotation.value())
            .getBeanDefinition();

        def.addQualifier(new AutowireCandidateQualifier(annotation.annotationType(), annotation.value()));

        registry.registerBeanDefinition(name, def);
    }
}
项目:hekate    文件:HekateLockServiceConfigurer.java   
@Override
protected void registerBeans(InjectLockRegion annotation, ResolvableType targetType, BeanDefinitionRegistry registry) {
    String name = LockRegionBean.class.getName() + "-" + annotation.value();

    if (!registry.containsBeanDefinition(name)) {
        AbstractBeanDefinition def = BeanDefinitionBuilder.rootBeanDefinition(LockRegionBean.class)
            .setLazyInit(true)
            .addPropertyValue("region", annotation.value())
            .getBeanDefinition();

        def.addQualifier(new AutowireCandidateQualifier(annotation.annotationType(), annotation.value()));

        registry.registerBeanDefinition(name, def);
    }
}
项目:springmock    文件:MockContextCustomizer.java   
private void registerDoubleDefinitionRegisteringProcessor(BeanDefinitionRegistry registry) {
    registry.registerBeanDefinition(DoubleRegisteringProcessor.BEAN_NAME, BeanDefinitionBuilder
            .rootBeanDefinition(DoubleRegisteringProcessor.class)
            .addConstructorArgReference(DoubleRegistry.BEAN_NAME)
            .addConstructorArgReference(DoubleDefinitionsRegistrationContext.BEAN_NAME)
            .getBeanDefinition());
}