人在江湖

            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 人在江湖 閱讀(4335) 評論(0)  編輯  收藏 所屬分類: spring
          主站蜘蛛池模板: 晴隆县| 大英县| 通山县| 临城县| 高密市| 凌海市| 尖扎县| 奉新县| 凤山县| 双柏县| 克拉玛依市| 新和县| 如东县| 滕州市| 齐齐哈尔市| 昌黎县| 嵊州市| 灌云县| 兴隆县| 大荔县| 施秉县| 闸北区| 黑山县| 福贡县| 楚雄市| 溧阳市| 富平县| 浦东新区| 长阳| 平舆县| 额敏县| 梁平县| 巨野县| 龙里县| 封丘县| 南江县| 锦州市| 长汀县| 黎川县| 南安市| 光泽县|