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)  編輯  收藏


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


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 浏阳市| 三门县| 贺州市| 易门县| 家居| 焦作市| 特克斯县| 冷水江市| 平泉县| 屏南县| 固原市| 育儿| 阜城县| 海宁市| 兴安县| 辽阳县| 鄂托克旗| 恭城| 富民县| 边坝县| 武隆县| 上高县| 德令哈市| 九寨沟县| 睢宁县| 威信县| 青浦区| 平顺县| 梁平县| 邯郸市| 澄城县| 永丰县| 揭西县| 教育| 盐山县| 阜平县| 海盐县| 淮滨县| 札达县| 福贡县| 临沧市|