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

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

Introduction

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

Prototype

void preInstantiateSingletons() throws BeansException;

Source Link

Document

Ensure that all non-lazy-init singletons are instantiated, also considering org.springframework.beans.factory.FactoryBean FactoryBeans .

Usage

From source file:org.springframework.context.support.AbstractApplicationContext.java

/**
 * Finish the initialization of this context's bean factory,
 * initializing all remaining singleton beans.
 *///  w ww. ja  v  a 2 s.  c  o  m
protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) {
    // Initialize conversion service for this context.
    if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME)
            && beanFactory.isTypeMatch(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)) {
        beanFactory.setConversionService(
                beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class));
    }

    // Register a default embedded value resolver if no bean post-processor
    // (such as a PropertyPlaceholderConfigurer bean) registered any before:
    // at this point, primarily for resolution in annotation attribute values.
    if (!beanFactory.hasEmbeddedValueResolver()) {
        beanFactory.addEmbeddedValueResolver(strVal -> getEnvironment().resolvePlaceholders(strVal));
    }

    // Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early.
    String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false);
    for (String weaverAwareName : weaverAwareNames) {
        getBean(weaverAwareName);
    }

    // Stop using the temporary ClassLoader for type matching.
    beanFactory.setTempClassLoader(null);

    // Allow for caching all bean definition metadata, not expecting further changes.
    beanFactory.freezeConfiguration();

    // Instantiate all remaining (non-lazy-init) singletons.
    beanFactory.preInstantiateSingletons();
}