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

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


          網站導航:
           
          主站蜘蛛池模板: 牙克石市| 海阳市| 通化市| 开江县| 商水县| 巴彦淖尔市| 安泽县| 海盐县| 罗平县| 健康| 绍兴市| 澄江县| 阳朔县| 芷江| 禄劝| 察哈| 香港| 凤山市| 清苑县| 铁岭县| 廊坊市| 兴和县| 西乌| 阜康市| 东丽区| 章丘市| 灌南县| 旌德县| 拜城县| 政和县| 西昌市| 汝州市| 会同县| 沈阳市| 鸡泽县| 杭州市| 贵州省| 乌拉特中旗| 华宁县| 准格尔旗| 师宗县|