Spring learning summary (2)

spring IoC container (inversion of control)
1. Manage application components using Dependency Injection (DI)

2. Container
BeanFactory container (provides support for dependency injection DI)
ApplicationContext container

3. Bean definition
class: mandatory, used to create a bean class
name: unique identifier, you can use ID or name to specify the bean identifier
lazy-initialization mode: lazy-initialized bean

4. The scope of the bean (scope property scope)
prototype: Force Spring to generate a new bean
every time it is needed singleton: Let Spring return the same bean every time it is needed
request
session
global-session

< bean id=”…” class=”…” scope=”prototype”>

5.Bean life cycle
(1) When a bean is instantiated, it may need to perform some initialization to make it into a usable state. Also, when the bean is no longer needed, and is removed from the container, some cleanup might need to be done.
(2) In order to define the installation and removal of a bean, we only need to declare it with init-method and/or destroy-method parameters. The init-method attribute specifies a method that is called immediately when the bean is instantiated. Likewise, destroy-method specifies a method that cannot be called until the bean is removed from the container.
< bean id=”exampleBean” class=”examples.ExampleBean” init-method=”init”/>

< bean id=”exampleBean” class=”examples.ExampleBean” destroy-method=”destroy”/>

6. bean definition inheritance
(1) bean definition can contain constructor parameters, property values, container specific information such as initialization method, static factory method name, and so on.

(2) The definition of the child bean inherits the configuration data of the parent definition.

(3) The parent bean itself cannot be instantiated because it is incomplete and it is also explicitly marked as abstract. When a definition is abstract, it is used only as a pure template bean definition, acting as a parent definition for child definitions.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325860897&siteId=291194637