本文整理汇总了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;
}
示例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);
}
示例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();
}
示例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));
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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");
}
}
示例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 + "]");
}
}
}
}
示例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);
}
}