人在江湖

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            82 Posts :: 10 Stories :: 169 Comments :: 0 Trackbacks

          轉載自 http://forum.springsource.org/showthread.php?t=50934

             1: class ExampleBean {
             2:   private String string;
             3:   public ExampleBean(String string) {
             4:     this.string = string;
             5:   }
             6:   
             7:   public void write() {
             8:     System.out.println("The text is: " + text);
             9:   }
            10:  
            11: }
            12:  
            13: class ExampleBeanFactory {
            14:   public static ExampleBean createExampleBean(String string) {
            15:     return new ExampleBean(string);
            16:   }
            17: }
            18:  
            19: public class Main {
            20:   public static void main(String[] args) {
            21:     ApplicationContext context = new ClassPathXmlApplicationContext(
            22:                     "context.xml");
            23:     ExampleBean exampleBean = 
            24:             ExampleBean)context.getBean("exampleBean", 
            25:               new Object[]{"bla bla"});
            26:     exampleBean.write();
            27:   }
            28: }
             1: <bean id="exampleBean" class="...ExampleBeanFactory"  scope="prototype"
             2:         factory-method="createExampleBean">
             3:     <constructor-arg value="default value"/>
             4: </bean>

           

          注意scope使用prototype

          posted on 2011-01-30 18:04 人在江湖 閱讀(4328) 評論(0)  編輯  收藏 所屬分類: spring
          主站蜘蛛池模板: 宝鸡市| 德阳市| 青海省| 调兵山市| 阜新| 辽宁省| 南川市| 合川市| 澄江县| 黄龙县| 慈利县| 林州市| 健康| 临泽县| 垦利县| 西青区| 南木林县| 宜昌市| 额济纳旗| 高碑店市| 北海市| 杨浦区| 三穗县| 新沂市| 监利县| 尖扎县| 维西| 溧水县| 丽水市| 南部县| 安西县| 溧阳市| 邓州市| 门头沟区| 开原市| 泰州市| 万安县| 安福县| 平陆县| 新晃| 贵港市|