Spring Learning Note (iii)--IOC container (ApplicationContext)

Source: Internet
Author: User

ApplicationContext

The ApplicationContext interface makes the Beanfactory sub-interface, which represents the context of an application.

ApplicationContext extends many of the features used, such as

    • Life cycle management of beans
    • Framework Event System
    • Internationalization support, etc.

At the same time, the ApplicationContext interface extends the functionality of Beanfactory by inheriting other interfaces:

    • Messagesource ——— provides international access for applications
    • Resourceloader ——— provide access support for resources such as URLs and file systems
    • Applicationeventpublisher ——— introduces event mechanisms, including startup events, shutdown events, and so on, allowing the container to provide support for application events in context.

The main implementation classes of ApplicationContext are

    • Classpathxmlapplicationcontext (The IOC configuration file is loaded from the classpath);
    • Filesystemxmlapplicationcontext (The IOC configuration file is loaded from the file system).
 PackageDemo02;ImportOrg.springframework.context.support.ClassPathXmlApplicationContext;/*** Created by Richard on 2017/7/24.*/ Public classApplicationcontextdemo { Public Static voidMain (string[] args) {Classpathxmlapplicationcontext context=NewClasspathxmlapplicationcontext ("Demo02/bean.xml"); Book Book= (book) Context.getbean ("book"));        System.out.println (Book.getname ());        System.out.println (Book.getauthor ());        System.out.println (Book.getpublisher ()); System.out.println (Book.getprice ());
Context.close (); }}

Because the Classpathxmlapplicationcontext class implements the Java.io.Closeable interface, it is necessary to call the close () method to close after the use is complete.

ApplicationContext && beanfactory Initialization differences

Beanfactory initializes the container so that the bean is not instantiated, and the target bean is not instantiated until the first time a bean is accessed.

ApplicationContext instantiates all single-instance beans when the context is initialized.

Bean's life cycle

  

Spring Learning Note (iii)--IOC container (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.