实例化bean的三种方式:

1。默认构造方法:

<bean id=''bean1" class="com.vv.Bean"/>

前提是已经有了Bean.class

2。静态工厂方法:

public class BeanFactory {
    public static Bean createBean(){
        return new Bean();
    }
  
}

<bean id=''bean1" class="com.vv.BeanFactory" factory-mothod="createBean"/>

3。实例工厂方法:

public class BeanFactory {
    public Bean createBean(){
        return new Bean();
    }
}

<bean id=''beanFactory" class="com.vv.BeanFactory"/>
<bean id="bean1" factory-bean="beanFactory" factory-mothod="createBean"/>


备注:默认情况下,如果一个bean的class、factory-bean、factory-method属性都指定后,工厂实例化方法优先

文章来源:http://x-spirit.spaces.live.com/Blog/cns!CC0B04AE126337C0!722.entry