隨筆 - 303  文章 - 883  trackbacks - 0
          <2007年9月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          30123456

          歡迎光臨! 
          閑聊 QQ:1074961813

          隨筆分類(357)

          我管理的群

          公共blog

          • n維空間
          • Email : java3d@126.com 群 : 12999758

          參與管理的論壇

          好友的blog

          我的其他blog

          朋友的網站

          搜索

          •  

          最新評論

          對于前個一代碼這個代碼加<ref bean=""/>使用和一些調試的System.out.println()從中你可以看到spring2.0的執行過程

          /src/applicationContext.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation
          ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

              
          <bean id="strvalue" class="com.lusm.spring.test.StrValue">
                  
          <property name="str">
                      
          <value>再見了!!!</value>
                  
          </property>       
              
          </bean>

              
          <bean id="hello" class="com.lusm.spring.test.Hello" abstract="false"
                  lazy-init
          ="default" autowire="default" dependency-check="default">
                  
          <property name="str">
                      
          <value>你好啊!!!</value>
                  
          </property>
                  
          <property name="sv">
                      
          <ref bean="strvalue" />
                  
          </property>
              
          </bean>

          </beans>

          /src/com/lusm/spring/test/StrValue.java

          package com.lusm.spring.test;

          public class StrValue {
              
              String str;
              
              StrValue()
          {
                  System.out.println(
          "StrValue class is builded");
              }

              
              
          public void SayGY(){
                  System.out.println(str);
              }


              
          public String getStr() {
                  
          return str;
              }


              
          public void setStr(String str) {
                  
          this.str = str;
              }

          }

          /src/com/lusm/spring/test/Hello.java

          package com.lusm.spring.test;

          public class Hello {
              
          private String str;
              
          private StrValue sv;

              
          public String getStr() {
                  System.out.println(
          "getStr");
                  
          return str;
              }


              
          public void setStr(String str) {
                  System.out.println(
          "setStr");
                  
          this.str = str;
              }


              
          public void sayHello() {
                  System.out.println(str);
              }


              
          public StrValue getSv() {
                  System.out.println(
          "getSv");
                  
          return sv;
              }


              
          public void setSv(StrValue sv) {
                  System.out.println(
          "setSv");
                  
          this.sv = sv;
              }


          }

          /src/com/lusm/spring/test/HelloTest.java

          package com.lusm.spring.test;

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

          public class HelloTest {

              
          public static void main(String[] args) {
                  ApplicationContext ac 
          = new FileSystemXmlApplicationContext(
                          
          "/src/applicationContext.xml");

                  Hello h 
          = (Hello) ac.getBean("hello");

                  System.out.println(h.getStr());
                  h.sayHello();

                  StrValue sv 
          = h.getSv();
                  sv.SayGY();
              }


          }

          執行結果

          log4j:WARN No appenders could be found for logger (org.springframework.context.support.FileSystemXmlApplicationContext).
          log4j:WARN Please initialize the log4j system properly.

          StrValue 
          class is builded
          setStr
          setSv
          getStr
          你好啊!!!
          你好啊!!!
          getSv
          再見了!!!




          地震讓大伙知道:居安思危,才是生存之道。
          posted on 2007-09-13 23:00 小尋 閱讀(415) 評論(0)  編輯  收藏 所屬分類: j2se/j2ee/j2me
          主站蜘蛛池模板: 永顺县| 潼南县| 娱乐| SHOW| 绥江县| 临泉县| 壤塘县| 无棣县| 石泉县| 宁蒗| 康保县| 无极县| 四会市| 汉寿县| 宁远县| 辉县市| 灯塔市| 禹城市| 马龙县| 汶上县| 诸暨市| 古田县| 五大连池市| 二连浩特市| 应用必备| 罗平县| 青浦区| 府谷县| 灯塔市| 山阳县| 壶关县| 保康县| 保亭| 浦江县| 邛崃市| 姚安县| 比如县| 神池县| 霸州市| 凌海市| 富锦市|