Bean of Spring Core component

Source: Internet
Author: User

Class hierarchies for the Beanbean of Spring core components

The top-level interface of the Bean is beanfactory, where the source is

/spring-framework/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java


The defaultlistablebeanfactory implements all the interfaces. But why do you need to define so many interfaces? To distinguish between the passing and conversion of spring's internal objects, the restrictions on the data access to the object. Listablebeanfactory indicates that these beans are a list, and hierarchicalbeanfactory that the beans are inherited. Autowirecapablebeanfactory defines the automatic assembly rules for these beans.

The Bean definition class hierarchy

The core is rootbeandefinition, in the source location is

/spring-framework/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java

When spring successfully resolves a

<bean></bean>

is transformed into a Beandefinition object within spring, after the nodes defined in the All subsequent operations are based on this object's

The parsing process of the bean

The parsing of the bean is mainly the parsing of the spring configuration file.

The status of Beans

The role of the bean in spring is like the role of OOP in Java, where there is no meaning for spring to exist without beans.

Spring solves an important problem by changing the dependency between objects into a configuration file, which is the dependency injection mechanism. Dependency injection is managed in spring's IOC container, and the main object of the IOC container is the bean.

Source

The following is the source code of Beanfactory, in Beanfactory only the basic behavior of the IOC container is defined, as to how to produce a specific bean, by Beanfactory implementation class concrete to achieve.

 Public  interface beanfactory {    /** * Here is the escape definition for Factorybean, because if the object retrieved Factorybean by using the bean's name is a factory-generated object, it needs to be escaped if the factory itself is needed .String Factory_bean_prefix ="&";//The Bean instance is given here in the IOC container, based on the name of the Bean, which is a large abstract factory. Object Getbean (String name)throwsBeansexception;//Here The Bean instance is obtained based on the Bean's name and class type, which throws an exception if the class type of the bean instance obtained by the name differs from the required one.<T> T Getbean (String name, class<t> requiredtype)throwsBeansexception; Object Getbean (String name, Object ... args)throwsBeansexception; <T> T Getbean (class<t> requiredtype, Object ... args)throwsBeansexception;//provide a search of the bean here to see if the bean in the IOC container has the name    BooleanContainsbean (String name);//The Bean instance is given here according to the Bean name, and at the same time to determine whether the bean is a singleton    BooleanIssingleton (String name)throwsNosuchbeandefinitionexception;//Determine if the bean with the given name is prototype    BooleanIsprototype (String name)throwsNosuchbeandefinitionexception;BooleanIstypematch (String name, Resolvabletype typetomatch)throwsNosuchbeandefinitionexception;//Determines if the bean of the given name matches the given type    BooleanIstypematch (String name, class<?> typetomatch)throwsNosuchbeandefinitionexception;//This is the class type that gets the bean instanceClass<?> GetType (String name)throwsNosuchbeandefinitionexception;//Get the Bean alias here, if it is retrieved by alias, then its original name will be retrieved.String[] Getaliases (String name);}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Bean of Spring Core component

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.