简体   繁体   中英

spring how to get BeanFactory from Application Context

I am a beginner in spring. Today, when I was reading the spring core document, I found the following instructions in chapter 1.3. Bean Overview

In addition to bean definitions that contain information on how to create a specific bean, the ApplicationContext implementations also permit the registration of existing objects that are created outside the container (by users). This is done by accessing the ApplicationContext's BeanFactory through the getBeanFactory() method, which returns the BeanFactory DefaultListableBeanFactory implementation. DefaultListableBeanFactory supports this registration through the registerSingleton(..) and registerBeanDefinition(..) methods. However, typical applications work solely with beans defined through regular bean definition metadata.

I instantiated an ApplicationContext object in IDEA with the following code, but I found that this object does not have a getBeanFactory() method:

ApplicationContext applicationContext = new ClassPathXmlApplicationContext("test.xml");

The document I read is the 5.3.5 version of spring, and I am using the same version of spring.

I guess if spring changed the ApplicationContext class and forgot to modify the document. Or is there something wrong with the object I instantiated?

Thanks in advance!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM