Bean of Spring Core Components
Bean of Spring Core Components
Bean class hierarchy
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. ListableBeanFactZ failed? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> vcnmx7cq + 1eLQqWJlYW7Kx7/struct + DQo8aDMgaWQ9" bean definition class hierarchy "> 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
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 = &; // here, according to the bean name, the bean instance is obtained in the IOC container, which 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 getBean (String name, Class
RequiredType) throws BeansException; Object getBean (String name, Object... args) throws BeansException;
T getBean (Class
RequiredType, Object... args) throws BeansException; // The bean retrieval is provided here to check whether the bean boolean containsBean (String name) with this name is available in the IOC container ); // 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
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 );}