Beanfactory VS ApplicationContext

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.