In short, the BeanFactory provides the configuration framework and basic functionality, and the ApplicationContext adds more enterprise-specific functionality. The ApplicationContext is a complete superset of the BeanFactory and is used exclusively in this chapter in descriptions of Spring’s IoC container
/** Cache of singleton objects: bean name to bean instance. */ privatefinal Map<String, Object> singletonObjects = newConcurrentHashMap<>(256);
/** Cache of singleton factories: bean name to ObjectFactory. */ privatefinal Map<String, ObjectFactory<?>> singletonFactories = newHashMap<>(16);
/** Cache of early singleton objects: bean name to bean instance. */ privatefinal Map<String, Object> earlySingletonObjects = newHashMap<>(16);
/** Set of registered singletons, containing the bean names in registration order. */ privatefinal Set<String> registeredSingletons = newLinkedHashSet<>(256);
/** Names of beans that are currently in creation. */ privatefinal Set<String> singletonsCurrentlyInCreation = Collections.newSetFromMap(newConcurrentHashMap<>(16));
/** Names of beans currently excluded from in creation checks. */ privatefinal Set<String> inCreationCheckExclusions = Collections.newSetFromMap(newConcurrentHashMap<>(16));
/** List of suppressed Exceptions, available for associating related causes. */ @Nullable private Set<Exception> suppressedExceptions;
/** Flag that indicates whether we're currently within destroySingletons. */ privatebooleansingletonsCurrentlyInDestruction=false;
/** Disposable bean instances: bean name to disposable instance. */ privatefinal Map<String, Object> disposableBeans = newLinkedHashMap<>();
/** Map between containing bean names: bean name to Set of bean names that the bean contains. */ privatefinal Map<String, Set<String>> containedBeanMap = newConcurrentHashMap<>(16);
/** Map between dependent bean names: bean name to Set of dependent bean names. */ privatefinal Map<String, Set<String>> dependentBeanMap = newConcurrentHashMap<>(64);
/** Map between depending bean names: bean name to Set of bean names for the bean's dependencies. */ privatefinal Map<String, Set<String>> dependenciesForBeanMap = newConcurrentHashMap<>(64); ... }
// org.springframework.beans.BeanUtils line 49 publicstatic <T> T instantiateClass(Constructor<T> ctor, Object... args)throws BeanInstantiationException { Assert.notNull(ctor, "Constructor must not be null");
/** * Actually performs context closing: publishes a ContextClosedEvent and * destroys the singletons in the bean factory of this application context. * <p>Called by both {@code close()} and a JVM shutdown hook, if any. * @see org.springframework.context.event.ContextClosedEvent * @see #destroyBeans() * @see #close() * @see #registerShutdownHook() */ protectedvoiddoClose() { // Publish shutdown event. publishEvent(newContextClosedEvent(this)); // Stop all Lifecycle beans, to avoid delays during individual destruction. this.lifecycleProcessor.onClose(); // Destroy all cached singletons in the context's BeanFactory. destroyBeans();
// Close the state of this context itself. closeBeanFactory();
// Let subclasses do some final clean-up if they wish... onClose(); } }