Bean of Spring Core Components and spring core bean

Source: Internet
Author: User

Bean of Spring Core Components and spring core bean
BeanBean class hierarchy of Spring Core Components

BeanFactory is the top-level interface of Bean, where the source code is

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


DefaultListableBeanFactory implements all interfaces. But why do we need to define so many interfaces? To differentiate the restrictions on Object Data access during the transmission and conversion of spring internal objects. ListableBeanFactory indicates that these beans are list-able, HierarchicalBeanFactory indicates that these beans are inherited, and AutowireCapableBeanFactory defines Automatic Assembly rules for these beans.

Bean definition class hierarchy

The core is RootBeanDefinition, where the source code is

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

When spring successfully parses

<bean></bean>

After the node is defined in, it is converted into a BeanDefinition object in spring. All subsequent operations are based on this object

Bean parsing process

Bean parsing mainly refers to parsing spring configuration files.

Bean status

Bean's role in spring is like the role of OOP for java. Without bean, there is no significance for spring.

Spring solves an important problem and transfers the dependency between objects to the configuration file for management, that is, the dependency injection mechanism. Dependency injection is managed in the spring IOC container, and the main operation object of the IOC container is bean.

Source code

The following is the BeanFactory source code. In BeanFactory, only the basic behavior of the IOC container is defined. As for how to generate a specific bean, it is implemented by the BeanFactory implementation class.

Public interface BeanFactory {/*** here is the escape definition of FactoryBean, because if you use the bean name to retrieve FactoryBean, the object is generated by the factory. If you need to get the factory itself, escape */String FACTORY_BEAN_PREFIX = "&"; // obtain the bean instance in the IOC container according to the bean name. This IOC container is a large abstract factory. Object getBean (String name) throws BeansException; // here, the bean instance is obtained based on the bean name and Class type. If the Class type of the bean Instance obtained based on the name is different from the expected Class type, it throws an exception <T> T getBean (String name, Class <T> requiredType) throws BeansException; Object getBean (String name, Object... args) throws BeansException; <T> T getBean (Class <T> requiredType, Object... args) throws BeansException; // The bean search is provided here to check whether the bean boolean containsBean (String Name); // obtain the bean instance based on the bean name and determine whether the bean is a singleton (String name) throws NoSuchBeanDefinitionException; // determine whether the bean with the given name is Prototype boolean isPrototype (String name) throws NoSuchBeanDefinitionException; boolean isTypeMatch (String name, ResolvableType typeToMatch) throws NoSuchBeanDefinitionException; // determine whether the bean with the given name matches the given type boolean isTypeMatch (String name, Class <?> TypeToMatch) throws NoSuchBeanDefinitionException; // Class of the bean instance <?> GetType (String name) throws NoSuchBeanDefinitionException; // The bean alias is obtained here. If the bean is retrieved Based on the alias, its original name will also be retrieved String [] getAliases (String name );}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.