當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。