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


Java ListableBeanFactory類代碼示例

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


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

示例1: getDataSourceBeanName

import org.springframework.beans.factory.ListableBeanFactory; //導入依賴的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: metricManager

import org.springframework.beans.factory.ListableBeanFactory; //導入依賴的package包/類
@Bean
public MetricManager metricManager() {

	String[] beanNames = ((ListableBeanFactory) beanFactory)
			.getBeanNamesForType(Metric.class);

	if (beanNames == null) {
		throw new RuntimeException(
				"At least 1 Metric bean must be specified");
	}

	Metric[] metrics = new Metric[beanNames.length];
	int i = 0;
	for (String metricName : beanNames) {
		metrics[i++] = beanFactory.getBean(metricName, Metric.class);
	}

	return new SimpleMetricManager(metrics);
}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:20,代碼來源:MetricsDI.java

示例3: setListableBeanFactory

import org.springframework.beans.factory.ListableBeanFactory; //導入依賴的package包/類
private void setListableBeanFactory() {
	ListableBeanFactory beanFactory = new StaticWebApplicationContext() {

		@Override
		public String[] getBeanNamesForType(Class<?> type,
				boolean includeNonSingletons, boolean allowEagerInit) {
			if (type.isAssignableFrom(
					ResourceServerTokenServicesConfiguration.class)) {
				return new String[] { "ResourceServerTokenServicesConfiguration" };
			}
			return new String[0];
		}

	};
	this.properties.setBeanFactory(beanFactory);
}
 
開發者ID:spring-projects,項目名稱:spring-security-oauth2-boot,代碼行數:17,代碼來源:ResourceServerPropertiesTests.java

示例4: main

import org.springframework.beans.factory.ListableBeanFactory; //導入依賴的package包/類
/**
 * @throws SQLException If Setup of emulation database failed, or if the
 *         application JDBC work fails.
 */
static public void main(String[] sa) throws SQLException {
    if (sa.length != 1) throw new IllegalArgumentException(SYNTAX_MSG);
    String authSpringFile = null;
    if (sa[0].equals("LDAP")) {
        authSpringFile = "ldapbeans.xml";
    } else if (sa[0].equals("JAAS")) {
        authSpringFile = "jaasbeans.xml";
    } else if (sa[0].equals("HsqldbSlave")) {
        authSpringFile = "slavebeans.xml";
    } else if (sa[0].equals("JAAS_LDAP")) {
        authSpringFile = "jaasldapbeans.xml";
    }
    if (authSpringFile == null)
        throw new IllegalArgumentException(SYNTAX_MSG);

    SpringExtAuth.prepMemoryDatabases(!sa[0].equals("HsqldbSlave"));
    ApplicationContext ctx =
        new ClassPathXmlApplicationContext("beandefs.xml", authSpringFile);
    ListableBeanFactory bf = (ListableBeanFactory) ctx;
    JdbcAppClass appBean = bf.getBean("appBean", JdbcAppClass.class);
    appBean.doJdbcWork();
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:27,代碼來源:SpringExtAuth.java

示例5: testAppContextClassHierarchy

import org.springframework.beans.factory.ListableBeanFactory; //導入依賴的package包/類
public void testAppContextClassHierarchy() {
	Class<?>[] clazz =
			ClassUtils.getClassHierarchy(OsgiBundleXmlApplicationContext.class, ClassUtils.ClassSet.ALL_CLASSES);

       //Closeable.class,
	Class<?>[] expected =
			new Class<?>[] { OsgiBundleXmlApplicationContext.class,
					AbstractDelegatedExecutionApplicationContext.class, AbstractOsgiBundleApplicationContext.class,
					AbstractRefreshableApplicationContext.class, AbstractApplicationContext.class,
					DefaultResourceLoader.class, ResourceLoader.class,
					AutoCloseable.class,
					DelegatedExecutionOsgiBundleApplicationContext.class,
					ConfigurableOsgiBundleApplicationContext.class, ConfigurableApplicationContext.class,
					ApplicationContext.class, Lifecycle.class, Closeable.class, EnvironmentCapable.class, ListableBeanFactory.class,
					HierarchicalBeanFactory.class, ApplicationEventPublisher.class, ResourcePatternResolver.class,
					MessageSource.class, BeanFactory.class, DisposableBean.class };

	assertTrue(compareArrays(expected, clazz));
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:20,代碼來源:ClassUtilsTest.java

示例6: findScheduler

import org.springframework.beans.factory.ListableBeanFactory; //導入依賴的package包/類
protected Scheduler findScheduler(String schedulerName) throws SchedulerException {
	if (this.beanFactory instanceof ListableBeanFactory) {
		ListableBeanFactory lbf = (ListableBeanFactory) this.beanFactory;
		String[] beanNames = lbf.getBeanNamesForType(Scheduler.class);
		for (String beanName : beanNames) {
			Scheduler schedulerBean = (Scheduler) lbf.getBean(beanName);
			if (schedulerName.equals(schedulerBean.getSchedulerName())) {
				return schedulerBean;
			}
		}
	}
	Scheduler schedulerInRepo = SchedulerRepository.getInstance().lookup(schedulerName);
	if (schedulerInRepo == null) {
		throw new IllegalStateException("No Scheduler named '" + schedulerName + "' found");
	}
	return schedulerInRepo;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:SchedulerAccessorBean.java

示例7: findEntityManagerFactory

import org.springframework.beans.factory.ListableBeanFactory; //導入依賴的package包/類
/**
 * Find an EntityManagerFactory with the given name in the given
 * Spring application context (represented as ListableBeanFactory).
 * <p>The specified unit name will be matched against the configured
 * persistence unit, provided that a discovered EntityManagerFactory
 * implements the {@link EntityManagerFactoryInfo} interface. If not,
 * the persistence unit name will be matched against the Spring bean name,
 * assuming that the EntityManagerFactory bean names follow that convention.
 * <p>If no unit name has been given, this method will search for a default
 * EntityManagerFactory through {@link ListableBeanFactory#getBean(Class)}.
 * @param beanFactory the ListableBeanFactory to search
 * @param unitName the name of the persistence unit (may be {@code null} or empty,
 * in which case a single bean of type EntityManagerFactory will be searched for)
 * @return the EntityManagerFactory
 * @throws NoSuchBeanDefinitionException if there is no such EntityManagerFactory in the context
 * @see EntityManagerFactoryInfo#getPersistenceUnitName()
 */
public static EntityManagerFactory findEntityManagerFactory(
		ListableBeanFactory beanFactory, String unitName) throws NoSuchBeanDefinitionException {

	Assert.notNull(beanFactory, "ListableBeanFactory must not be null");
	if (StringUtils.hasLength(unitName)) {
		// See whether we can find an EntityManagerFactory with matching persistence unit name.
		String[] candidateNames =
				BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, EntityManagerFactory.class);
		for (String candidateName : candidateNames) {
			EntityManagerFactory emf = (EntityManagerFactory) beanFactory.getBean(candidateName);
			if (emf instanceof EntityManagerFactoryInfo) {
				if (unitName.equals(((EntityManagerFactoryInfo) emf).getPersistenceUnitName())) {
					return emf;
				}
			}
		}
		// No matching persistence unit found - simply take the EntityManagerFactory
		// with the persistence unit name as bean name (by convention).
		return beanFactory.getBean(unitName, EntityManagerFactory.class);
	}
	else {
		// Find unique EntityManagerFactory bean in the context, falling back to parent contexts.
		return beanFactory.getBean(EntityManagerFactory.class);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:43,代碼來源:EntityManagerFactoryUtils.java

示例8: isBeanRegistered

import org.springframework.beans.factory.ListableBeanFactory; //導入依賴的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

示例9: registerBeanDefinitions

import org.springframework.beans.factory.ListableBeanFactory; //導入依賴的package包/類
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
	// Register JPA Datastore (transactional)
	if (beanFactory instanceof ListableBeanFactory) {
		String[] emfBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
				(ListableBeanFactory) beanFactory, EntityManagerFactory.class, true, false);
		if (emfBeanNames == null || emfBeanNames.length == 0) {
			emfBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors((ListableBeanFactory) beanFactory,
					AbstractEntityManagerFactoryBean.class, true, false);
		}
		if (emfBeanNames != null && emfBeanNames.length == 1) {
			String emfBeanName = (emfBeanNames[0].startsWith("&")) ? emfBeanNames[0].substring(1) : emfBeanNames[0];
			JpaDatastoreRegistrar.registerDatastore(registry, null, PrimaryMode.AUTO, emfBeanName, true, false,
					beanClassLoader);
		}
	}
}
 
開發者ID:holon-platform,項目名稱:holon-datastore-jpa,代碼行數:18,代碼來源:JpaDatastoreAutoConfigurationRegistrar.java

示例10: addParameter

import org.springframework.beans.factory.ListableBeanFactory; //導入依賴的package包/類
public void addParameter(Object askFor, Object valueParam)
throws InstantiationException, IllegalAccessException {
    try {
        Class clz = ClassUtils.forName((String)askFor);
        if (log.isDebugEnabled()) {
            log.debug("trying to resolve the following class from the Spring bean container: " + clz.getName());
        }

        Map beansOfType = ((ListableBeanFactory)beanFactory).getBeansOfType(clz);
        if (log.isDebugEnabled()) {
            log.debug("beans: " + beansOfType + " - " + beansOfType.size());
        }
        if (beansOfType.size() == 0) {
            log.debug("adding parameter the normal way");
            super.addParameter(askFor, valueParam);
        } else if (beansOfType.size() > 1) {
            // TODO: handle multiple declarations
            throw new InstantiationException("multiple beans of type '" + clz.getName() + "' were found in the spring configuration");
        } else {
            this.beans.put(askFor, beansOfType.values().iterator().next());
        }
    } catch (ClassNotFoundException e) {
        super.addParameter(askFor, valueParam);
    }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:26,代碼來源:SpringContainer.java

示例11: getBeanNames

import org.springframework.beans.factory.ListableBeanFactory; //導入依賴的package包/類
public Collection getBeanNames()
{
    List names = new ArrayList();

    // Snarf the beans from Spring
    if (beanFactory instanceof ListableBeanFactory)
    {
        ListableBeanFactory listable = (ListableBeanFactory) beanFactory;
        names.addAll(Arrays.asList(listable.getBeanDefinitionNames()));
    }
    else
    {
        log.warn("List of beanNames does not include Spring beans since your BeanFactory is not a ListableBeanFactory.");
    }

    // And append the DWR ones
    names.addAll(super.getBeanNames());

    return Collections.unmodifiableCollection(names);
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:21,代碼來源:SpringContainer.java

示例12: configureDatastore

import org.springframework.beans.factory.ListableBeanFactory; //導入依賴的package包/類
/**
 * Register {@link DatastoreResolver}s bean into given <code>datastore</code>.
 * @param datastore Datastore
 * @param datastoreBeanName Datastore bean name
 * @param factory BeanFactory
 */
public static void configureDatastore(Datastore datastore, String datastoreBeanName, BeanFactory factory) {
	ObjectUtils.argumentNotNull(datastore, "Null Datastore");
	ObjectUtils.argumentNotNull(datastoreBeanName, "Null Datastore bean name");
	ObjectUtils.argumentNotNull(factory, "Null BeanFactory");

	if (factory instanceof ListableBeanFactory) {
		configureDatastoreResolvers(datastore, datastoreBeanName, (ListableBeanFactory) factory);
		configureDatastoreCommodityFactories(datastore, datastoreBeanName, (ListableBeanFactory) factory);
		configureDatastorePostProcessors(datastore, datastoreBeanName, (ListableBeanFactory) factory);
	} else {
		LOGGER.warn(
				"The BeanFactory [" + factory + "] is not a ListableBeanFactory: skipping Datastore configuration");
	}

}
 
開發者ID:holon-platform,項目名稱:holon-core,代碼行數:22,代碼來源:DatastoreInitializer.java

示例13: configureDatastoreResolvers

import org.springframework.beans.factory.ListableBeanFactory; //導入依賴的package包/類
/**
 * Register {@link DatastoreResolver} annotated beans as <code>datastore</code> {@link ExpressionResolver}s.
 * @param datastore Datastore to configure
 * @param datastoreBeanName Datastore bean name to configure
 * @param beanFactory Bean factory
 */
private static void configureDatastoreResolvers(Datastore datastore, String datastoreBeanName,
		ListableBeanFactory beanFactory) {
	final String[] beanNames = beanFactory.getBeanNamesForAnnotation(DatastoreResolver.class);
	if (beanNames != null && beanNames.length > 0) {
		for (String beanName : beanNames) {
			if (!ExpressionResolver.class.isAssignableFrom(beanFactory.getType(beanName))) {
				throw new BeanNotOfRequiredTypeException(beanName, ExpressionResolver.class,
						beanFactory.getType(beanName));
			}
			DatastoreResolver dr = beanFactory.findAnnotationOnBean(beanName, DatastoreResolver.class);
			String datastoreRef = AnnotationUtils.getStringValue(dr.datastoreBeanName());
			if (datastoreRef == null || datastoreRef.equals(datastoreBeanName)) {
				// register resolver
				ExpressionResolver<?, ?> resolver = (ExpressionResolver<?, ?>) beanFactory.getBean(beanName);
				datastore.addExpressionResolver(resolver);
				LOGGER.debug(() -> "Registered expression resolver [" + resolver.getClass().getName()
						+ "] into Datastore with bean name [" + datastoreBeanName + "]");
			}
		}
	}
}
 
開發者ID:holon-platform,項目名稱:holon-core,代碼行數:28,代碼來源:DatastoreInitializer.java

示例14: registerBeanDefinitions

import org.springframework.beans.factory.ListableBeanFactory; //導入依賴的package包/類
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

	if (beanFactory instanceof ListableBeanFactory) {

		String[] dataSourceBeanNames = ((ListableBeanFactory) beanFactory).getBeanNamesForType(DataSource.class,
				false, true);
		if (dataSourceBeanNames != null) {
			for (String dataSourceBeanName : dataSourceBeanNames) {
				BeanDefinition bd = registry.getBeanDefinition(dataSourceBeanName);
				if (bd instanceof DataContextBoundBeanDefinition) {
					DataSourceRegistrar.registerDataSourceTransactionManager(registry, dataSourceBeanName,
							((DataContextBoundBeanDefinition) bd).getDataContextId().orElse(null),
							PrimaryMode.AUTO);
				}
			}
		}

	}

}
 
開發者ID:holon-platform,項目名稱:holon-jdbc,代碼行數:22,代碼來源:DataSourcesTransactionManagerAutoConfigurationRegistrar.java

示例15: afterPropertiesSet

import org.springframework.beans.factory.ListableBeanFactory; //導入依賴的package包/類
@Override
public void afterPropertiesSet() throws Exception {
    if (beanFactory instanceof ListableBeanFactory) {
        Map<String, HandlerMethodArgumentResolver> instances =
                ((ListableBeanFactory) this.beanFactory).getBeansOfType(HandlerMethodArgumentResolver.class);
        if (null != instances && instances.size() > 0) {
            handlerMethodArgumentResolvers.addAll(instances.values());
        }
    }

    if (null == messageHandlerMethodFactory) {
        messageHandlerMethodFactory = createDefaultJmsHandlerMethodFactory();
    }

    if (endpointRegistry instanceof JmsListenerEndpointRegistryAdapter) {
        JmsListenerEndpointRegistryAdapter methodEndpointRegistry =
                (JmsListenerEndpointRegistryAdapter) endpointRegistry;
        methodEndpointRegistry.setMessageHandlerMethodFactory(messageHandlerMethodFactory);
    }
}
 
開發者ID:kinglcc,項目名稱:spring-boot-jms,代碼行數:21,代碼來源:MethodJmsListenerConfigurer.java


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