Spring Framework: bean life cycle

bean life cycle

1, bean is created (using the constructor)

2, bean initialization

3, bean method execution

4, bean destruction

. 1   public  void demoTest3 () {
 2                   // call the constructor herein, and performs initialization method of the setUp 
. 3           the ClassPathXmlApplicationContext AC = new new the ClassPathXmlApplicationContext ( "the applicationContext.xml" );
 . 4           StuDAO studao = (StuDAO) ac.getBean ( "StuDAO" ) ;
 . 5           studao.foo (); // method performed 
. 6           ac.close (); // the bean is destroyed 
7       }

 

 

1  / * 
2  * execution order:
 3  * constructor is performed
 4  * initialized. . .
5  * method calls the
 6  * been destroyed. . .
. 7  *
 . 8  * 
 . 9   * / 
10  public  class StuDAOImpl the implements StuDAO {
 . 11      public StuDAOImpl () {
 12 is          System.out.println ( "construction method is performed" );
 13 is      }
 14  
15      public  void the setUp () {
 16          the System.out. the println ( "initialized ..." );
 17      }
 18 
. 19      @Override
 20 is      public  void foo () {
 21 is          System.out.println ( "method calls" );
 22 is          
23 is      }
 24      
25      public  void setDown () {
 26 is          System.out.println ( "... is destroyed." );
 27      }
 28  
29 }

 

Guess you like

Origin www.cnblogs.com/noperx/p/11269334.html