Follow the new Brother study Spring Framework--spring container (ii)

Source: Internet
Author: User

Spring container Start Spring container (Instantiate container)

--The IOC container reads the bean configuration before creating the bean instance, it must be instantiated (loaded to start) so that the instance of the bean can be fetched and used.

Beans are the basic unit of spring management, and any Java objects and components are treated as beans, and the container is responsible for managing the dependencies between beans and beans.

Two types of startup implementations

1. Beanfactory: The basic implementation of the IOC container is the infrastructure of the spring framework, facing spring itself;

-The most basic interface of the spring container is beanfactor. Beanfactory is responsible for configuring, creating, and managing beans.

--The Beanfactory interface contains several basic methods:

Øboolean Containbean (String name): Determines whether the spring container contains a bean instance with ID name.

Ø<t> Getbean (class<t> REQUIREDTYPR): Gets the unique bean instance in the spring container that belongs to the Requiredtype type.

Øobject Getbean (String name): Returns a bean instance with ID name in the Spring container.

Ø<t> T Getbean (String name,class requiredtype): Returns a bean with the ID name in the container and a type of requiredtype

Øclass <?> GetType (String name): Returns the type of the specified bean instance in the container.

2, ApplicationContext: for developers using the spring framework, almost all applications use it rather than the underlying beanfactory;

--ApplicationContext is beanfactory sub-interface, generally use applicationcontext, in use compared to beanfactory more convenient.

Look at the structure can see that applicationcontext has 1 sub-interfaces, multiple abstract classes, 2 implementation classes

1) One sub-interface: Configurableapplicationcontext

① This interface adds two main methods refresh and close, allowing ApplicationContext to have the ability to start, refresh, and close the context

2) Two implementation classes: Classpathxmlapplicationcontext and Filesystemxmlapplicationcontext

    ①classpathxmlapplicationcontext: Loading a configuration file from a Classpath

    

√ File path: Default refers to the project under the Classpath path, so do not need to write the prefix classpath:. If you point to an absolute path, you need to add File:

    ②filesystemxmlapplicationcontext: Loading configuration files from the file system

    

√ File path: Default refers to the project root directory, want to use the project's classpath path below, need to add classpath:.

--------------------------------------------------------------------------------------------------------------- -----

Follow the new brother. Spring Frame series: Follow new brother to learn Spring framework--Create HelloWorld project (i) Follow the new Brother study Spring Framework--spring container (ii) follow the new brother. Learn Spring Framework--Configure beans with XML (iii) follow the new brother to learn Spring framework--Configuring beans by Annotations (iv) Follow the new Brother study Spring Framework--AOP (v)

Follow the new Brother study Spring Framework--spring container (ii)

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.