当前位置: 首页>>代码示例>>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;未经允许,请勿转载。