Example usage for org.springframework.beans.factory.support DefaultListableBeanFactory setInstantiationStrategy

List of usage examples for org.springframework.beans.factory.support DefaultListableBeanFactory setInstantiationStrategy

Introduction

In this page you can find the example usage for org.springframework.beans.factory.support DefaultListableBeanFactory setInstantiationStrategy.

Prototype

public void setInstantiationStrategy(InstantiationStrategy instantiationStrategy) 

Source Link

Document

Set the instantiation strategy to use for creating bean instances.

Usage

From source file:com.liferay.arkadiko.bean.AKBeanPostProcessor.java

/**
 * Post process bean factory.//  w  ww.ja v  a  2 s.  c o m
 *
 * @param beanFactory the bean factory
 * @throws BeansException the beans exception
 */
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    if (!(beanFactory instanceof DefaultListableBeanFactory)) {
        return;
    }

    DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) beanFactory;

    defaultListableBeanFactory.setInstantiationStrategy(this);

    AutowireCandidateResolver autowireCandidateResolver = defaultListableBeanFactory
            .getAutowireCandidateResolver();

    defaultListableBeanFactory
            .setAutowireCandidateResolver(new AKAutowireCandidateResolver(autowireCandidateResolver));

    for (String beanName : defaultListableBeanFactory.getBeanDefinitionNames()) {

        BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);

        if (!(beanDefinition instanceof AbstractBeanDefinition)) {
            continue;
        }

        String className = beanDefinition.getBeanClassName();

        if (className == null) {
            continue;
        }

        try {
            AKBeanDefinition akBeanDefinition = new AKBeanDefinition(this,
                    (AbstractBeanDefinition) beanDefinition, beanName, getServiceRegistry());

            defaultListableBeanFactory.removeBeanDefinition(beanName);

            defaultListableBeanFactory.registerBeanDefinition(beanName, akBeanDefinition);
        } catch (Exception e) {
            if (_log.isLoggable(Level.SEVERE)) {
                _log.log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }
}