当前位置: 首页>>代码示例>>Java>>正文


Java BeanDefinitionRegistry.containsBeanDefinition方法代码示例

本文整理汇总了Java中org.springframework.beans.factory.support.BeanDefinitionRegistry.containsBeanDefinition方法的典型用法代码示例。如果您正苦于以下问题:Java BeanDefinitionRegistry.containsBeanDefinition方法的具体用法?Java BeanDefinitionRegistry.containsBeanDefinition怎么用?Java BeanDefinitionRegistry.containsBeanDefinition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.beans.factory.support.BeanDefinitionRegistry的用法示例。


在下文中一共展示了BeanDefinitionRegistry.containsBeanDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDataSourceBeanName

import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:26,代码来源:JpaRegistrar.java

示例2: registerBeanDefinitionIfNotExists

import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
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;
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:21,代码来源:BeanRegistrationUtil.java

示例3: registerBeans

import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:29,代码来源:HekateRpcServiceConfigurer.java

示例4: isBeanRegistered

import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
/**
 * Checks if a bean of given type and bound to given data context id is already registered
 * @param beanFactory Bean factory
 * @param registry Bean registry
 * @param type Bean type to check
 * @param dataContextId Data context id
 * @param defaultBeanName Default bean name to check
 * @return The registered bean name if found, <code>null</code> otherwise
 */
private static String isBeanRegistered(ListableBeanFactory beanFactory, BeanDefinitionRegistry registry,
		Class<?> type, String dataContextId, String defaultBeanName) {
	String[] beanNames = beanFactory.getBeanNamesForType(type);
	if (beanNames != null && beanNames.length > 0) {
		for (String beanName : beanNames) {
			BeanDefinition bd = registry.getBeanDefinition(beanName);
			if (bd instanceof DataContextBoundBeanDefinition) {
				String did = ((DataContextBoundBeanDefinition) bd).getDataContextId().orElse(null);
				if ((dataContextId == null && did == null)
						|| (dataContextId != null && dataContextId.equals(did))) {
					return beanName;
				}
			} else {
				if (dataContextId == null) {
					return beanName;
				}
			}
		}
	}
	if (defaultBeanName != null && registry.containsBeanDefinition(defaultBeanName)) {
		return defaultBeanName;
	}
	return null;
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jpa,代码行数:34,代码来源:JpaAutoConfigurationRegistrar.java

示例5: registerBeans

import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
@Override
protected void registerBeans(InjectLock annotation, ResolvableType targetType, BeanDefinitionRegistry registry) {
    String name = LockBean.class.getName() + "-" + annotation.name() + "--" + annotation.name();

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

        AutowireCandidateQualifier qualifier = new AutowireCandidateQualifier(annotation.annotationType());
        qualifier.addMetadataAttribute(new BeanMetadataAttribute("region", annotation.region()));
        qualifier.addMetadataAttribute(new BeanMetadataAttribute("name", annotation.name()));

        def.addQualifier(qualifier);

        registry.registerBeanDefinition(name, def);
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:21,代码来源:HekateLockServiceConfigurer.java

示例6: generateBeanName

import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
protected String generateBeanName(String prefix, BeanDefinition def, ParserContext parserContext) {
	BeanDefinitionRegistry registry = parserContext.getRegistry();
	String name = prefix + BeanDefinitionReaderUtils.generateBeanName(def, registry);
	String generated = name;
	int counter = 0;

	while (registry.containsBeanDefinition(generated)) {
		generated = name + BeanFactoryUtils.GENERATED_BEAN_NAME_SEPARATOR + counter;
		if (parserContext.isNested()) {
			generated = generated.concat("#generated");
		}
		counter++;
	}

	return generated;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:17,代码来源:AbstractReferenceDefinitionParser.java

示例7: findParentDefinition

import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
private BeanDefinition findParentDefinition(String parentName, BeanDefinitionRegistry registry)
{   
    if (registry != null) 
    {
        if (registry.containsBeanDefinition(parentName)) 
        {
            return registry.getBeanDefinition(parentName);
        } 
        else if (registry instanceof HierarchicalBeanFactory) 
        {
            // Try to get parent definition from the parent BeanFactory. This could return null
            BeanFactory parentBeanFactory = ((HierarchicalBeanFactory)registry).getParentBeanFactory();
            return findParentDefinition(parentName, (BeanDefinitionRegistry)parentBeanFactory);
        } 
    }
    
    // we've exhausted all possibilities        
    return null;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:20,代码来源:DwrNamespaceHandler.java

示例8: parse

import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
@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;
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:29,代码来源:FieldDefineBeanDefinitionParser.java

示例9: registerConfigBeanPropertyResolver

import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
/**
 * 注册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());
    }
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:12,代码来源:ConfigBeanConfigUtils.java

示例10: registerConfigBeanConversionService

import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
/**
 * 注册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());
    }
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:12,代码来源:ConfigBeanConfigUtils.java

示例11: registerBeanDefinitions

import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
/**
 * 注册beans
 *
 * @param registry
 */
private void registerBeanDefinitions(BeanDefinitionRegistry registry) {
    String beanName = PropertiesFileConfigItemPostProcessor.class.getName();
    if (!registry.containsBeanDefinition(beanName)) {
        BeanDefinitionBuilder bean = BeanDefinitionBuilder.genericBeanDefinition(PropertiesFileConfigItemPostProcessor.class);
        registry.registerBeanDefinition(beanName, bean.getBeanDefinition());
    }
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:13,代码来源:ConfigContext.java

示例12: registerBeansForRoot

import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
@Override
public void registerBeansForRoot(BeanDefinitionRegistry registry, RepositoryConfigurationSource config) {
    super.registerBeansForRoot(registry, config);

    if (!registry.containsBeanDefinition("documentDbMappingContext")) {
        final RootBeanDefinition definition = new RootBeanDefinition(DocumentDbMappingContext.class);
        definition.setRole(AbstractBeanDefinition.ROLE_INFRASTRUCTURE);
        definition.setSource(config.getSource());

        registry.registerBeanDefinition("documentDbMappingContext", definition);
    }
}
 
开发者ID:Microsoft,项目名称:spring-data-documentdb,代码行数:13,代码来源:DocumentDbRepositoryConfigurationExtension.java

示例13: registerBeans

import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
@Override
protected void registerBeans(InjectConnector annotation, ResolvableType targetType, BeanDefinitionRegistry registry) {
    String name = NetworkConnectorBean.class.getName() + "-" + annotation.value();

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

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

        registry.registerBeanDefinition(name, def);
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:16,代码来源:HekateNetworkServiceConfigurer.java

示例14: registerBeans

import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:16,代码来源:HekateLocalMetricsServiceConfigurer.java

示例15: registerBeans

import org.springframework.beans.factory.support.BeanDefinitionRegistry; //导入方法依赖的package包/类
@Override
protected void registerBeans(InjectChannel annotation, ResolvableType targetType, BeanDefinitionRegistry registry) {
    String name = MessagingChannelBean.class.getName() + "-" + annotation.value();

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

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

        registry.registerBeanDefinition(name, def);
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:16,代码来源:HekateMessagingServiceConfigurer.java


注:本文中的org.springframework.beans.factory.support.BeanDefinitionRegistry.containsBeanDefinition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。