Xml格式的应用启动6
第十一步:finishBeanFactoryInitialization(beanFactory),实例化非懒加载的单例Bean。
protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) {
// 为当前context设置ConversionService
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));
}
// 设置占位符解析器,主要是为了解析注解中出现的形如${...}的字符,将其替换为具体的值
if (!beanFactory.hasEmbeddedValueResolver()) {
beanFactory.addEmbeddedValueResolver(strVal -> getEnvironment().resolvePlaceholders(strVal));
}
// 实例化LoadTimeWeaverAware
String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false);
for (String weaverAwareName : weaverAwareNames) {
getBean(weaverAwareName);
}
beanFactory.setTempClassLoader(null);
// 冻结所有的bean definitions,不允许之后再对BeanDefinition进行修改
beanFactory.freezeConfiguration();
// 实例化所有的非懒加载的单例Bean
beanFactory.preInstantiateSingletons();
}