licheng700

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            26 Posts :: 5 Stories :: 5 Comments :: 1 Trackbacks

          package net.spring.test;

          import java.lang.reflect.Method;

          import net.spring.util.LogInitiate;
          import net.spring.util.Logger;

          import org.springframework.context.ApplicationContext;
          import org.springframework.context.support.FileSystemXmlApplicationContext;

          /**
           * @author chengli 無侵入式的可擴展框架:無需代碼中涉及Spring類,即可納入Spring容器進行管理
           *         核心類BeanFactory作為依賴注入機制的實現基礎
           */
          public class QuickStart {

           public static void main(String[] args) {

            // BasicConfigurator.configure();
            LogInitiate.initialize();
            Logger logger = new Logger(QuickStart.class);
            try {
             ApplicationContext ctx = new FileSystemXmlApplicationContext(
               "bean.xml");
             // 從ctx中讀取的配置信息區分大小寫
             // Spring通過依賴注入機制,將依賴關系從編碼中脫離,從而大大降低組件之間的耦合
             // 通過接口來將調用者和實現者分離
             Action action = (Action) ctx.getBean("UpperAction");
             logger.info(action.execute(" Mis JohSon"));
             action = (Action) ctx.getBean("LowerAction");
             logger.info(action.execute(" Mis JohSon"));
            } catch (Exception e) {
             // e.printStackTrace();
             logger.error(e.getMessage());
            }
           }

           public Object reflection(String className,String methodName ,String nameValue) {
            Class cls;
            Object obj = null;
            try {
             cls = Class.forName(className);
             Method mtd = cls.getMethod(methodName, new Class[] { String.class });
             obj = (Object) cls.newInstance();
             mtd.invoke(obj, new Object[] { nameValue });
             return obj;
            } catch (Exception e) {
             e.printStackTrace();
            }
            return obj;
           }
          }

          posted on 2005-09-06 08:39 小海船 閱讀(282) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 高密市| 湖北省| 绵阳市| 普兰店市| 瑞昌市| 海伦市| 宜兰市| 波密县| 元氏县| 梧州市| 辛集市| 隆回县| 平利县| 葫芦岛市| 曲阜市| 桂平市| 旺苍县| 会泽县| 海南省| 兴义市| 白银市| 布拖县| 安仁县| 太康县| 民县| 康平县| 耿马| 吴川市| 宁德市| 伊宁市| 蓝山县| 阿克| 宁城县| 萨嘎县| 宜都市| 宁晋县| 夏邑县| 江口县| 罗城| 丰宁| 阿巴嘎旗|