What are the roles and differences between Beanfactory and ApplicationContext in spring?

Source: Internet
Author: User

Role:

1. The beanfactory is responsible for reading the bean configuration document, managing the bean's loading, instantiating, maintaining the dependency between the beans, and responsible for the bean's declaration cycle.
2. ApplicationContext provides more complete framework functionality in addition to the functionality provided by the beanfactory above:

A. Internationalization support
B. Resource access: Resource rs = ctx. GetResource ("Classpath:config.properties"), "File:c:/config.properties"
C. Event delivery: By implementing the Applicationcontextaware interface
3. Common ways to get ApplicationContext:
Filesystemxmlapplicationcontext: Created from a file system or URL-specified XML configuration file with an array of configuration file names or file names
Classpathxmlapplicationcontext: Created from the classpath XML configuration file, you can read the configuration file from the jar package
Webapplicationcontextutils: Reading a configuration file from the Web application's root directory requires a configuration in XML. config, which can be configured with a listener or servlet to implement

<Listener><Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class></Listener><servlet><Servlet-name>Context</Servlet-name><Servlet-class>Org.springframework.web.context.ContextLoaderServlet</Servlet-class><Load-on-startup>1</Load-on-startup></servlet>


Either way, the default profile is Web-inf/applicationcontext.xml, or you can use Context-param to specify the configuration file

< Context-param > < Param-name >contextconfiglocation</param-name><Param-value  >/web-inf/myapplicationcontext.xml</param-value> </ Context-param >

What are the roles and differences between Beanfactory and ApplicationContext in spring?

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.