Example usage for org.springframework.beans.factory.config ConfigurableListableBeanFactory registerScope

List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory registerScope

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config ConfigurableListableBeanFactory registerScope.

Prototype

void registerScope(String scopeName, Scope scope);

Source Link

Document

Register the given scope, backed by the given Scope implementation.

Usage

From source file:org.os890.adapter.cdi.springmvc.BeanFactoryAwareBeanFactoryPostProcessor.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    for (String beanName : currentBeanFactory.get().getBeanDefinitionNames()) {
        ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(beanName,
                currentBeanFactory.get().getBeanDefinition(beanName));
    }/*from  w ww .ja v a  2s.  c  o m*/
    String bridgeScopeName = CdiSpringScope.class.getName();
    beanFactory.registerScope(bridgeScopeName, currentBeanFactory.get().getRegisteredScope(bridgeScopeName));
}

From source file:com.vaadin.spring.internal.UIScopeImpl.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory)
        throws BeansException {
    LOGGER.debug("Registering Vaadin UI scope with bean factory [{}]", configurableListableBeanFactory);
    configurableListableBeanFactory.registerScope(VAADIN_UI_SCOPE_NAME, this);
}

From source file:org.os890.ds.addon.spring.impl.CdiAwareBeanFactoryPostProcessor.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry) beanFactory;

    try {/*from   w  w  w  .j  a v a 2 s  .c o  m*/
        for (Bean<?> bean : this.cdiBeansForSpringRegistration.values()) {
            BeanDefinition beanDefinition = createSpringBeanDefinition(bean);
            String beanName = createBeanName(bean, beanDefinition, beanDefinitionRegistry);
            beanDefinitionRegistry.registerBeanDefinition(beanName, beanDefinition);
        }

        beanFactory.registerScope(CdiSpringScope.class.getName(),
                new CdiSpringScope(this.beanManager, this.cdiBeansForSpringRegistration));
    } catch (Exception e) {
        throw ExceptionUtils.throwAsRuntimeException(e);
    }
}

From source file:org.granite.client.tide.spring.SpringContextManager.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    beanFactory.registerSingleton("context", getContext());
    EntityManager entityManager = getContext().getEntityManager();
    entityManager.addListener(new SpringDataConflictListener());
    beanFactory.registerSingleton("entityManager", entityManager);
    beanFactory.registerSingleton("dataManager", getContext().getDataManager());
    for (Entry<String, Object> entry : getContext().getInitialBeans().entrySet())
        beanFactory.registerSingleton(entry.getKey(), entry.getValue());
    beanFactory.registerScope("view", new ViewScope());
}

From source file:org.springframework.amqp.rabbit.stocks.context.RefreshScope.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    beanFactory.registerScope(name, this);
    setSerializationId(beanFactory);/*from w  ww  . j a v  a 2 s .  c om*/

    this.beanFactory = beanFactory;

    evaluationContext = new StandardEvaluationContext();
    evaluationContext.addPropertyAccessor(new BeanFactoryAccessor());

    Assert.state(beanFactory instanceof BeanDefinitionRegistry,
            "BeanFactory was not a BeanDefinitionRegistry, so RefreshScope cannot be used.");
    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;

    for (String beanName : beanFactory.getBeanDefinitionNames()) {
        BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
        // Replace this or any of its inner beans with scoped proxy if it
        // has this scope
        boolean scoped = name.equals(definition.getScope());
        Scopifier scopifier = new Scopifier(registry, name, proxyTargetClass, scoped);
        scopifier.visitBeanDefinition(definition);
        if (scoped) {
            createScopedProxy(beanName, definition, registry, proxyTargetClass);
        }
    }

}

From source file:org.springframework.batch.core.partition.gemfire.RemoteScope.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    beanFactory.registerScope(name, this);

    this.beanFactory = beanFactory;
    evaluationContext = new StandardEvaluationContext();
    evaluationContext.addPropertyAccessor(new BeanFactoryAccessor());

    Assert.state(beanFactory instanceof BeanDefinitionRegistry,
            "BeanFactory was not a BeanDefinitionRegistry, so RefreshScope cannot be used.");
    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;

    String id = this.id;
    if (id == null) {
        String names = Arrays.asList(registry.getBeanDefinitionNames()).toString();
        logger.debug("Generating bean factory id from names: " + names);
        id = UUID.nameUUIDFromBytes(names.getBytes()).toString();
        logger.debug("Generated bean factory id: " + id);
    }//w  w  w  .j a v  a  2  s .c  om

    Assert.state(beanFactory instanceof BeanDefinitionRegistry,
            "BeanFactory was not a DefaultListableBeanFactory, so RefreshScope cannot be used.");
    ((DefaultListableBeanFactory) beanFactory).setSerializationId(id);

    for (String beanName : beanFactory.getBeanDefinitionNames()) {
        BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
        // Replace this or any of its inner beans with scoped proxy if it
        // has this scope
        boolean scoped = name.equals(definition.getScope());
        Scopifier scopifier = new Scopifier(registry, name, proxyTargetClass, scoped);
        scopifier.visitBeanDefinition(definition);
        if (scoped) {
            createScopedProxy(beanName, definition, registry, proxyTargetClass);
        }
    }

}

From source file:org.springframework.cloud.context.scope.GenericScope.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    beanFactory.registerScope(name, this);
    setSerializationId(beanFactory);//www .j a  v  a2s.  co m

    this.beanFactory = beanFactory;

    evaluationContext = new StandardEvaluationContext();
    evaluationContext.addPropertyAccessor(new BeanFactoryAccessor());

    if (!autoProxy) {
        // No need to try and create proxies
        return;
    }

    Assert.state(beanFactory instanceof BeanDefinitionRegistry,
            "BeanFactory was not a BeanDefinitionRegistry, so RefreshScope cannot be used.");
    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;

    for (String beanName : beanFactory.getBeanDefinitionNames()) {
        BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
        // Replace this or any of its inner beans with scoped proxy if it
        // has this scope
        boolean scoped = name.equals(definition.getScope());
        Scopifier scopifier = new Scopifier(registry, name, proxyTargetClass, scoped);
        scopifier.visitBeanDefinition(definition);
        if (scoped) {
            createScopedProxy(beanName, definition, registry, proxyTargetClass);
        }
    }

}

From source file:org.vaadin.spring.internal.VaadinUIScope.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    logger.debug(String.format("Registering UI scope with beanFactory [%s]", beanFactory));
    beanFactory.registerScope(UI_SCOPE_NAME, this);
}