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 楊軍威 閱讀(349) 評論(0)  編輯  收藏


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


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 鄄城县| 同德县| 浮梁县| 乃东县| 南京市| 泽普县| 开江县| 枣阳市| 万盛区| 名山县| 凯里市| 澎湖县| 亚东县| 和静县| 防城港市| 东兰县| 德保县| 万宁市| 无棣县| 乳山市| 太谷县| 西藏| 镇安县| 嘉禾县| 兴国县| 东城区| 永川市| 呼玛县| 富宁县| 通州市| 女性| 宁都县| 镇康县| 霍林郭勒市| 舟山市| 马关县| 澎湖县| 库伦旗| 南皮县| 屏南县| 彭泽县|