org.springframework.beans.factory.BeanFactoryis the actual representative of the spring IoC container ,
The IOC container is responsible for accommodating the beans described earlier and managing the beans.
In spring, BeanFactory it is the core interface of the IOC container. Its responsibilities include: instantiation, positioning, configuration
The objects in the application and the dependencies between those objects.
Spring provides us with a number of easy-to-use BeanFactory implementations, the XmlBeanFactory most common one.
The implementation will describe the objects that comprise the application in XML to
And the dependencies between objects. XmlBeanFactoryclass will get this XML configuration metadata and use it to build a complete
A fully configurable system or application.
Beanfactory provides an advanced configuration mechanism that makes it possible to manage a variety of objects. ApplicationContext
Is BeanFactory extended, features are further enhanced, such as easier integration with spring AOP, resource handling
(International processing), event delivery, and context implementations of various application tiers (e.g. for Web applications WebApplicationContext ).
In short, the BeanFactory formulation framework and basic functions are provided, while the ApplicationContext additional
More features that support enterprise core content. ApplicationContextis fully BeanFactory expanded,
Therefore BeanFactory , the ability and behavior can also be applied to ApplicationContext .
An getBean(String) instance of the bean can be obtained using BeanFactory the method, and the method provided is extremely simple. BeanFactoryinterfaces provide a lot of methods, but for our applications it's best to never call them, and of course to use them, to getBean(String) avoid our reliance on the Spring API.
Beanfactory also does not have the ability to compile the spring configuration file if ApplicationContext error occurs when the container is initialized
Beanfactory cannot be detected in time, you must wait for the first instance of the bean to throw an exception
such as instantiation of beanfactory
Resource res = new Filesystemresource ("Applicationcontext.xml");
Beanfactory factory = new Xmlbeanfactory (res);
Resource Resclasspath = new Classpathresource ("ApplicationContext.xml.xml");
Beanfactory Factory2 = new Xmlbeanfactory (Resclasspath);
Cannot check for errors when obtaining beanfactory instances
User u= (user) U.getbean ("User");
An exception can be thrown when an object instance is obtained
and instantiate ApplicationContext
ApplicationContext context=new classpathxmlapplicationcontext ("Applicationcontext.xml");
You can throw an exception directly.
Beanfactory VS ApplicationContext