Management details of the bean spring

The control object to spring to manage,

 

spring对bean的管理细节
        1、创建的三种方式
        2、bean镀锡的作用范围
        3、bean对象的什么周期

 

  1. Three ways to create
        <!--    第一种方式,适用默认构造方法创建
                在spring的配置文件中适用bean标签,配以id和class属性之后,且没有其他属性和标签时,
                采用的就是默认构造函数创建bean对象,此时如果类中没有默认构造函数,则对象无法创建。
        -->
        <!--<bean id="getInstance" class="com.spring.service.impl.AccountServiceImpl"></bean>-->
    
        <!-- 第二种方式, 使用普通工厂中的方法创建对象(使用某个类中的方法创建对象,并存入spring容器)  -->
    <!--    <bean id="instanceFactory" class="com.spring.factory.InstanceFactory"></bean>
        <bean id="getInstance" factory-bean="instanceFactory" factory-method="getAccountDao"></bean>-->
    
    
        <!-- 第三种方式,使用工厂中的静态方法创建对象(使用某个类中的静态方法创建对象,并存入spring容器) -->
          <bean id="getInstance" class="com.spring.factory.StaticFactory" factory-method="getAccountDao"></bean>
  2. bean adjustment range of action
    
    
    scope bean tag label,
    Function: Used to specify the scope bean
    Value:
        singleton: (default) singleton
        prototype: Multi embodiment
        request: requesting application range acting wen
        session: session scope is acting in web application
        global-session: When acting on the scope of the session cluster environment (global session scope), does not make a cluster environment, he is the session
  3. What bean object cycle
    
    
    Singleton object
         Birth: When the container to create objects of birth
         Alive: as long as the container is still the object has been alive
         Death: container destroyed, the object of death
         Summary: The same container, and life cycle of singletons
    Many cases of Object
         Birth: When we use the object to create a framework for our spring
         Alive: as long as the object is in use has been alive
         Death: When the object is not a long time, and no other object references, the process of java garbage collection
Published 158 original articles · won praise 26 · views 90000 +

Guess you like

Origin blog.csdn.net/qq_41650354/article/details/103745521
Recommended