java學習

          java學習

           

          spring使用靜態工廠方法來實例化bean

          public class Person1 implements Person{

           private Person1(String s){
            System.out.println(s);
           }

           public void say() {
            System.out.println("00000000000000");  
           }
           public static Person1 getPerson1(){
            return new Person1("pppppppppp");
            
           }
          }


          <bean id="person" class="com.yjw.bean.Person1" factory-method="getPerson1">

          public class Test {

           public static void main(String[] args) {
            ApplicationContext  ctx =new  ClassPathXmlApplicationContext("applicationContext.xml");
           // UserService userservice =(UserService) ctx.getBean("person");
            /* User u = new User();
            u.setUsername("qq");
            u.setPassword("qq");
            userservice.save(u);*/
            Person person =  (Person) ctx.getBean("person");
            person.say();
            
           }
           
          }

          posted on 2013-04-22 22:52 楊軍威 閱讀(347) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 阿克苏市| 哈巴河县| 金湖县| 夹江县| 芦溪县| 尤溪县| 阿合奇县| 长沙县| 息烽县| 洛隆县| 玛纳斯县| 武汉市| 丹凤县| 达孜县| 龙里县| 宜昌市| 莱阳市| 兴业县| 耒阳市| 长岛县| 普兰店市| 和林格尔县| 泰宁县| 新竹县| 田东县| 汪清县| 岐山县| 伊川县| 治多县| 磐安县| 玉树县| 阜南县| 绵阳市| 平定县| 十堰市| 宜章县| 通海县| 乳源| 大城县| 依兰县| 晋中市|