本文整理匯總了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;
}
示例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;
}
示例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;
}