人在江湖

            BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
            82 Posts :: 10 Stories :: 169 Comments :: 0 Trackbacks

          轉(zhuǎn)載自 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) 評(píng)論(0)  編輯  收藏 所屬分類: spring
          主站蜘蛛池模板: 甘泉县| 石城县| 西青区| 壤塘县| 太保市| 周宁县| 苏尼特右旗| 政和县| 宜川县| 佛坪县| 商都县| 绍兴市| 潍坊市| 济宁市| 罗定市| 呼图壁县| 前郭尔| 塔河县| 石家庄市| 丰县| 镇原县| 琼中| 乳山市| 巨鹿县| 沂南县| 吉木乃县| 大竹县| 上虞市| 新乡县| 罗城| 巨野县| 云安县| 平安县| 阿克苏市| 徐汇区| 江阴市| 弋阳县| 桂林市| 汝阳县| 合肥市| 曲周县|