当前位置: 首页>>代码示例>>Java>>正文


Java ConfigurableListableBeanFactory.getBean方法代码示例

本文整理汇总了Java中org.springframework.beans.factory.config.ConfigurableListableBeanFactory.getBean方法的典型用法代码示例。如果您正苦于以下问题:Java ConfigurableListableBeanFactory.getBean方法的具体用法?Java ConfigurableListableBeanFactory.getBean怎么用?Java ConfigurableListableBeanFactory.getBean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.beans.factory.config.ConfigurableListableBeanFactory的用法示例。


在下文中一共展示了ConfigurableListableBeanFactory.getBean方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: postProcessBeanFactory

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //导入方法依赖的package包/类
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {

    Iterator<String> iterator = configurableListableBeanFactory.getBeanNamesIterator();

    while (iterator.hasNext()) {
        Object obj = configurableListableBeanFactory.getBean(iterator.next());

        Field[] fields = obj.getClass().getDeclaredFields();
        for (Field field : fields) {
            if (field.getType().isAnnotationPresent(ConfigBean.class)) {
                field.setAccessible(true);
                try {
                    Object value = config.configBeanParser(field.getType()).getConfigBean();
                    field.set(obj, value);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }

        }
    }

}
 
开发者ID:ChenXun1989,项目名称:ace,代码行数:25,代码来源:ConfigBeanFactoryPostProcessor.java

示例2: initApplicationEventMulticaster

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //导入方法依赖的package包/类
/**
 * Initialize the ApplicationEventMulticaster.
 * Uses SimpleApplicationEventMulticaster if none defined in the context.
 * @see org.springframework.context.event.SimpleApplicationEventMulticaster
 */
protected void initApplicationEventMulticaster() {
	ConfigurableListableBeanFactory beanFactory = getBeanFactory();
	if (beanFactory.containsLocalBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME)) {
		this.applicationEventMulticaster =
				beanFactory.getBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, ApplicationEventMulticaster.class);
		if (logger.isDebugEnabled()) {
			logger.debug("Using ApplicationEventMulticaster [" + this.applicationEventMulticaster + "]");
		}
	}
	else {
		this.applicationEventMulticaster = new SimpleApplicationEventMulticaster(beanFactory);
		beanFactory.registerSingleton(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, this.applicationEventMulticaster);
		if (logger.isDebugEnabled()) {
			logger.debug("Unable to locate ApplicationEventMulticaster with name '" +
					APPLICATION_EVENT_MULTICASTER_BEAN_NAME +
					"': using default [" + this.applicationEventMulticaster + "]");
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:AbstractApplicationContext.java

示例3: initLifecycleProcessor

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //导入方法依赖的package包/类
/**
 * Initialize the LifecycleProcessor.
 * Uses DefaultLifecycleProcessor if none defined in the context.
 * @see org.springframework.context.support.DefaultLifecycleProcessor
 */
protected void initLifecycleProcessor() {
	ConfigurableListableBeanFactory beanFactory = getBeanFactory();
	if (beanFactory.containsLocalBean(LIFECYCLE_PROCESSOR_BEAN_NAME)) {
		this.lifecycleProcessor =
				beanFactory.getBean(LIFECYCLE_PROCESSOR_BEAN_NAME, LifecycleProcessor.class);
		if (logger.isDebugEnabled()) {
			logger.debug("Using LifecycleProcessor [" + this.lifecycleProcessor + "]");
		}
	}
	else {
		DefaultLifecycleProcessor defaultProcessor = new DefaultLifecycleProcessor();
		defaultProcessor.setBeanFactory(beanFactory);
		this.lifecycleProcessor = defaultProcessor;
		beanFactory.registerSingleton(LIFECYCLE_PROCESSOR_BEAN_NAME, this.lifecycleProcessor);
		if (logger.isDebugEnabled()) {
			logger.debug("Unable to locate LifecycleProcessor with name '" +
					LIFECYCLE_PROCESSOR_BEAN_NAME +
					"': using default [" + this.lifecycleProcessor + "]");
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:AbstractApplicationContext.java

示例4: qualifiedBeanOfType

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //导入方法依赖的package包/类
/**
 * Obtain a bean of type {@code T} from the given {@code BeanFactory} declaring a qualifier
 * (e.g. {@code <qualifier>} or {@code @Qualifier}) matching the given qualifier).
 * @param bf the BeanFactory to get the target bean from
 * @param beanType the type of bean to retrieve
 * @param qualifier the qualifier for selecting between multiple bean matches
 * @return the matching bean of type {@code T} (never {@code null})
 * @throws NoSuchBeanDefinitionException if no matching bean of type {@code T} found
 */
private static <T> T qualifiedBeanOfType(ConfigurableListableBeanFactory bf, Class<T> beanType, String qualifier) {
	Map<String, T> candidateBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(bf, beanType);
	T matchingBean = null;
	for (String beanName : candidateBeans.keySet()) {
		if (isQualifierMatch(qualifier, beanName, bf)) {
			if (matchingBean != null) {
				throw new NoSuchBeanDefinitionException(qualifier, "No unique " + beanType.getSimpleName() +
						" bean found for qualifier '" + qualifier + "'");
			}
			matchingBean = candidateBeans.get(beanName);
		}
	}
	if (matchingBean != null) {
		return matchingBean;
	}
	else if (bf.containsBean(qualifier)) {
		// Fallback: target bean at least found by bean name - probably a manually registered singleton.
		return bf.getBean(qualifier, beanType);
	}
	else {
		throw new NoSuchBeanDefinitionException(qualifier, "No matching " + beanType.getSimpleName() +
				" bean found for qualifier '" + qualifier + "' - neither qualifier match nor bean name match!");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:BeanFactoryAnnotationUtils.java

示例5: postProcessBeanFactory

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //导入方法依赖的package包/类
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    BeanDefinitionRegistry registry=(BeanDefinitionRegistry)beanFactory;
    CuratorFramework curatorFramework = beanFactory.getBean(CuratorFramework.class);
    ServiceRouter serviceRouter = beanFactory.getBean(ServiceRouter.class);
    for(Class clazz:list){
        GenericBeanDefinition definition=(GenericBeanDefinition) BeanDefinitionBuilder.genericBeanDefinition(clazz).getBeanDefinition();
        definition.getPropertyValues().addPropertyValue("innerClass",clazz);
        definition.getPropertyValues().addPropertyValue("factory",beanFactory);
        ServiceApi serviceApi = map.get(clazz.getName());
        definition.getPropertyValues().addPropertyValue("proccessName",serviceApi.getName());

        String path = "/"+clazz.getName()+"/"+ (serviceApi!=null ? serviceApi.getVersion() :
                ThriftConstant.DEFAULT_VERSION);
        ServiceDiscover serviceDiscover = new ZookeeperServiceDiscover(curatorFramework, path);

        definition.getPropertyValues().addPropertyValue("serverManager",
                new ServerManager(serviceDiscover, serviceRouter));

        definition.setBeanClass(ProxyFactoryBean.class);
        definition.setDestroyMethodName("close");
        registry.registerBeanDefinition(clazz.getName(), definition);
    }

}
 
开发者ID:somewhereMrli,项目名称:albedo-thrift,代码行数:25,代码来源:ServiceStarter.java

示例6: initMessageSource

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //导入方法依赖的package包/类
/**
 * Initialize the MessageSource.
 * Use parent's if none defined in this context.
 */
protected void initMessageSource() {
	ConfigurableListableBeanFactory beanFactory = getBeanFactory();
	if (beanFactory.containsLocalBean(MESSAGE_SOURCE_BEAN_NAME)) {
		this.messageSource = beanFactory.getBean(MESSAGE_SOURCE_BEAN_NAME, MessageSource.class);
		// Make MessageSource aware of parent MessageSource.
		if (this.parent != null && this.messageSource instanceof HierarchicalMessageSource) {
			HierarchicalMessageSource hms = (HierarchicalMessageSource) this.messageSource;
			if (hms.getParentMessageSource() == null) {
				// Only set parent context as parent MessageSource if no parent MessageSource
				// registered already.
				hms.setParentMessageSource(getInternalParentMessageSource());
			}
		}
		if (logger.isDebugEnabled()) {
			logger.debug("Using MessageSource [" + this.messageSource + "]");
		}
	}
	else {
		// Use empty MessageSource to be able to accept getMessage calls.
		DelegatingMessageSource dms = new DelegatingMessageSource();
		dms.setParentMessageSource(getInternalParentMessageSource());
		this.messageSource = dms;
		beanFactory.registerSingleton(MESSAGE_SOURCE_BEAN_NAME, this.messageSource);
		if (logger.isDebugEnabled()) {
			logger.debug("Unable to locate MessageSource with name '" + MESSAGE_SOURCE_BEAN_NAME +
					"': using default [" + this.messageSource + "]");
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:AbstractApplicationContext.java

示例7: createSqlSessionFactory

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; //导入方法依赖的package包/类
private @Nullable
SqlSessionFactory createSqlSessionFactory(
    ConfigurableListableBeanFactory configurableListableBeanFactory,
    String prefixName, MybatisProperties mybatisProperties) {
  DataSource dataSource = configurableListableBeanFactory
      .getBean(prefixName + "Ds", DataSource.class);

  SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
  sqlSessionFactoryBean.setDataSource(dataSource);
  sqlSessionFactoryBean.setVfs(LocSpringBootVFS.class);
  Optional.ofNullable(mybatisProperties.getConfigLocation()).map(this.resourceLoader::getResource)
      .ifPresent(sqlSessionFactoryBean::setConfigLocation);

  org.apache.ibatis.session.Configuration configuration = mybatisProperties.getConfiguration();
  if (configuration == null && !StringUtils.hasText(mybatisProperties.getConfigLocation())) {
    configuration = new org.apache.ibatis.session.Configuration();
  }

  sqlSessionFactoryBean.setConfiguration(configuration);
  Optional.ofNullable(mybatisProperties.getConfigurationProperties())
      .ifPresent(sqlSessionFactoryBean::setConfigurationProperties);
  Optional.ofNullable(mybatisProperties.getTypeAliasesPackage())
      .ifPresent(sqlSessionFactoryBean::setTypeAliasesPackage);
  Optional.ofNullable(mybatisProperties.getTypeHandlersPackage())
      .ifPresent(sqlSessionFactoryBean::setTypeHandlersPackage);
  if (!ObjectUtils.isEmpty(mybatisProperties.resolveMapperLocations())) {
    sqlSessionFactoryBean.setMapperLocations(mybatisProperties.resolveMapperLocations());
  }

  try {
    SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBean.getObject();
    if (sqlSessionFactory == null) {
      log.error("sqlSessionFactoryBean get object is null");
      return null;
    }
    register(configurableListableBeanFactory, sqlSessionFactory, prefixName + "SessionFactory",
        prefixName + "Sf");

    if (!Strings.isNullOrEmpty(mybatisProperties.getBasePackage())) {
      createBasePackageScanner((BeanDefinitionRegistry) configurableListableBeanFactory,
          mybatisProperties.getBasePackage(), prefixName);
    } else {
      createClassPathMapperScanner((BeanDefinitionRegistry) configurableListableBeanFactory,
          prefixName);
    }
    return sqlSessionFactory;
  } catch (Exception e) {
    log.error(e.getMessage(), e);
  }
  return null;
}
 
开发者ID:lord-of-code,项目名称:loc-framework,代码行数:52,代码来源:LocMybatisAutoConfiguration.java


注:本文中的org.springframework.beans.factory.config.ConfigurableListableBeanFactory.getBean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。