當前位置: 首頁>>代碼示例>>Java>>正文


Java BeanDefinition.isPrimary方法代碼示例

本文整理匯總了Java中org.springframework.beans.factory.config.BeanDefinition.isPrimary方法的典型用法代碼示例。如果您正苦於以下問題:Java BeanDefinition.isPrimary方法的具體用法?Java BeanDefinition.isPrimary怎麽用?Java BeanDefinition.isPrimary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.beans.factory.config.BeanDefinition的用法示例。


在下文中一共展示了BeanDefinition.isPrimary方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getPrimaryBeans

import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
private List<String> getPrimaryBeans(ConfigurableListableBeanFactory beanFactory,
                                     List<String> beanNames, boolean considerHierarchy) {
    List<String> primaryBeans = new ArrayList<String>();
    for (String beanName : beanNames) {
        BeanDefinition beanDefinition = findBeanDefinition(beanFactory, beanName, considerHierarchy);
        if (beanDefinition != null && beanDefinition.isPrimary()) {
            primaryBeans.add(beanName);
        }
    }
    return primaryBeans;
}
 
開發者ID:drtrang,項目名稱:spring-boot-autoconfigure,代碼行數:12,代碼來源:OnBeansCondition.java

示例2: registerDatastore

import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
/**
 * Register a {@link JpaDatastore} bean
 * @param registry BeanDefinitionRegistry
 * @param dataContextId Data context id
 * @param primaryMode Primary mode
 * @param entityManagerFactoryBeanName EntityManagerFactory bean name reference
 * @param transactional Whether to add transactional behaviour to transactional datastore methods
 * @param beanClassLoader Bean class loader
 * @return Registered Datastore bean name
 */
public static String registerDatastore(BeanDefinitionRegistry registry, String dataContextId,
		PrimaryMode primaryMode, String entityManagerFactoryBeanName, boolean transactional, boolean autoFlush,
		ClassLoader beanClassLoader) {

	boolean primary = PrimaryMode.TRUE == primaryMode;
	if (!primary && PrimaryMode.AUTO == primaryMode) {
		if (registry.containsBeanDefinition(entityManagerFactoryBeanName)) {
			BeanDefinition bd = registry.getBeanDefinition(entityManagerFactoryBeanName);
			primary = bd.isPrimary();
		}
	}

	GenericDataContextBoundBeanDefinition definition = new GenericDataContextBoundBeanDefinition();
	definition.setDataContextId(dataContextId);

	Class<?> datastoreClass = transactional
			? addTransactionalAnnotations(DefaultSpringJpaDatastore.class, dataContextId, beanClassLoader)
			: DefaultSpringJpaDatastore.class;

	definition.setBeanClass(datastoreClass);

	definition.setAutowireCandidate(true);
	definition.setPrimary(primary);
	definition.setDependsOn(entityManagerFactoryBeanName);

	if (dataContextId != null) {
		definition.addQualifier(new AutowireCandidateQualifier(Qualifier.class, dataContextId));
	}

	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("entityManagerFactory", new RuntimeBeanReference(entityManagerFactoryBeanName));
	pvs.add("autoFlush", autoFlush);
	definition.setPropertyValues(pvs);

	String beanName = BeanRegistryUtils.buildBeanName(dataContextId,
			EnableJpaDatastore.DEFAULT_DATASTORE_BEAN_NAME);

	registry.registerBeanDefinition(beanName, definition);

	StringBuilder log = new StringBuilder();
	if (dataContextId != null) {
		log.append("<Data context id: ");
		log.append(dataContextId);
		log.append("> ");
	}
	log.append("Registered JPA Datastore bean with name \"");
	log.append(beanName);
	log.append("\"");
	if (dataContextId != null) {
		log.append(" and qualifier \"");
		log.append(dataContextId);
		log.append("\"");
	}
	log.append(" bound to EntityManagerFactory bean: ");
	log.append(entityManagerFactoryBeanName);
	logger.info(log.toString());

	return beanName;

}
 
開發者ID:holon-platform,項目名稱:holon-datastore-jpa,代碼行數:71,代碼來源:JpaDatastoreRegistrar.java

示例3: registerDataSourceTransactionManager

import org.springframework.beans.factory.config.BeanDefinition; //導入方法依賴的package包/類
/**
 * Register a {@link PlatformTransactionManager} bound to given {@link DataSource} bean name
 * @param registry Bean definitions registry
 * @param dataSourceBeanName DataSource bean name
 * @param dataContextId Data context id
 * @param primaryMode Primary mode
 * @return Registered transaction manager bean name
 */
public static String registerDataSourceTransactionManager(BeanDefinitionRegistry registry,
		String dataSourceBeanName, String dataContextId, PrimaryMode primaryMode) {

	boolean primary = PrimaryMode.TRUE == primaryMode;
	if (PrimaryMode.AUTO == primaryMode && registry.containsBeanDefinition(dataSourceBeanName)) {
		BeanDefinition bd = registry.getBeanDefinition(dataSourceBeanName);
		if (bd.isPrimary()) {
			primary = true;
		}
	}

	GenericDataContextBoundBeanDefinition definition = new GenericDataContextBoundBeanDefinition();
	definition.setDataContextId(dataContextId);
	definition.setAutowireCandidate(true);
	definition.setPrimary(primary);
	definition.setBeanClass(DataSourceTransactionManager.class);

	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("dataSource", new RuntimeBeanReference(dataSourceBeanName));
	definition.setPropertyValues(pvs);

	if (dataContextId != null) {
		definition.addQualifier(new AutowireCandidateQualifier(Qualifier.class, dataContextId));
	}

	String tmBeanName = BeanRegistryUtils.buildBeanName(dataContextId,
			EnableDataSource.DEFAULT_TRANSACTIONMANAGER_BEAN_NAME);

	registry.registerBeanDefinition(tmBeanName, definition);

	StringBuilder log = new StringBuilder();
	if (dataContextId != null) {
		log.append("<Data context id: ");
		log.append(dataContextId);
		log.append("> ");
	}
	log.append("Registered DataSourceTransactionManager bean with name \"");
	log.append(tmBeanName);
	log.append("\"");
	if (dataContextId != null) {
		log.append(" and qualifier \"");
		log.append(dataContextId);
		log.append("\"");
	}
	LOGGER.info(log.toString());

	return tmBeanName;
}
 
開發者ID:holon-platform,項目名稱:holon-jdbc,代碼行數:57,代碼來源:DataSourceRegistrar.java


注:本文中的org.springframework.beans.factory.config.BeanDefinition.isPrimary方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。