<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Ryan's Java world!

    something about Java and opensource!

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      51 Posts :: 25 Stories :: 59 Comments :: 0 Trackbacks

    By : icess ,我的部落格 http://blog.matrix.org.cn/page/icess

    在考試前匆匆看了一遍Spring in Action 也沒有記錄什么,考試結束了,要抓緊時間整理一下.要不然就忘了.^_^:

    整理一下我目前可能會用到的模塊, 對于那些現在根本用不到的冬冬還是等有時間再研究吧!

    第一個當然是最經典的HelloWorld 了 , 呵呵,簡單,但是說明了原理.

    定義一個服務接口

    package? test.helloworld;

    public?interface? GreetingService?{
    ?? public?void? sayGreeting();

    }

    下面是其實現:

    package? test.helloworld;

    public?class? GreetingServiceImpl? implements? GreetingService?{

    ?? private? String?greeting;
    ?? public? GreetingServiceImpl()?{}
    ?? public? GreetingServiceImpl(String?greeting)?{
    ???? this .greeting?=?greeting;
    ?? }
    ?? public?void? sayGreeting()?{
    ???? //??Auto-generated?method?stub
    ???? System.out.println(greeting);
    ?? }
    ??
    ?? public?void? setGreeting(String?greeting)?{
    ???? this .greeting?=?greeting;
    ?? }

    }

    然后就是測試 IoC 的測試代碼:

    package? test.helloworld;


    import? org.springframework.beans.factory.BeanFactory;
    import? org.springframework.beans.factory.xml.XmlBeanFactory;
    import? org.springframework.context.ApplicationContext;
    import? org.springframework.context.support.ClassPathXmlApplicationContext;
    import? org.springframework.core.io.FileSystemResource;

    public?class? HelloApp?{

    ?? /**
    ??? *? @param? args
    ??? */
    ?? public?static?void? main(String[]?args)?{
    ???? //?TODO?Auto-generated?method?stub
    //????BeanFactory?factory;
    //????factory?=?new?XmlBeanFactory(new?FileSystemResource("src/test/helloworld/hello.xml"));
    ???? //?使用不同的方法得到bean.?(BeanFactory?or?ApplicationContext)
    ???? ApplicationContext?context?=? new? ClassPathXmlApplicationContext( "test/helloworld/hello.xml" );
    ????
    ????
    ???? GreetingService?greetingService?=?(GreetingService)?context.getBean( "greetingService" );
    //????GreetingService?greetingService?=?(GreetingService)?factory.getBean("greetingService");
    ???? greetingService.sayGreeting();
    ?? }

    }

    還有重要的配置文件如下:hello.xml

    <?

    xml version = "1.0" encoding = "UTF-8" ?>

    <!

    DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"

    "http://www.springframework.org/dtd/spring-beans.dtd" >

    <

    beans >

    < bean id = "greetingService"

    class = "test.helloworld.GreetingServiceImpl" >

    < property name = "greeting" >

    < value > ice rain ! </ value >

    </ property >

    </ bean >

    </

    beans >

    呵呵就這么簡單,實現了 greeting 屬性的 Ioc.

    這是Spring 兩大基本支柱其一的工作原理, 關于AoP的內容,在這里不作討論,因為現在我使用AoP的地方不是很多,簡單的應用是很簡單的啦.^_^.

    下面一篇我們來看看 在spring包裝下的jdbc訪問. 詳細情況也可以參考這里

    posted on 2006-05-22 14:13 冰雨 閱讀(1905) 評論(0)  編輯  收藏 所屬分類: Spring

    JSF中文技術文摘
    主站蜘蛛池模板: 亚洲视频在线免费| 九九久久国产精品免费热6| 毛茸茸bbw亚洲人| 免费看少妇作爱视频| 国产精品视频免费观看| 污污网站免费观看| 国产特黄特色的大片观看免费视频| 亚洲国产日韩a在线播放| 亚洲乱码日产精品BD在线观看| 亚洲成A人片在线观看WWW| 亚洲国产av无码精品| 日本成人免费在线| 成人爽A毛片免费看| 在线看免费观看AV深夜影院| 99xxoo视频在线永久免费观看| A国产一区二区免费入口| 一级黄色免费大片| 无忧传媒视频免费观看入口| 亚洲av永久无码精品秋霞电影秋| 中文字幕亚洲情99在线| 99热亚洲色精品国产88| 亚洲人成电影在线观看青青| 亚洲系列国产精品制服丝袜第| 久久精品国产亚洲AV高清热| 亚洲日韩图片专区第1页| 亚洲AV无码精品无码麻豆| 亚洲大尺度无码无码专区| 久久久青草青青亚洲国产免观| 亚洲中文字幕无码一久久区| 亚洲色爱图小说专区| 久久精品国产亚洲AV麻豆王友容| 国产亚洲精品无码成人| 久久久久久a亚洲欧洲aⅴ| 亚洲bt加勒比一区二区| 亚洲国产精品久久久久久| 久久亚洲精精品中文字幕| 亚洲福利电影在线观看| 亚洲av乱码一区二区三区| 亚洲色www永久网站| 亚洲精品国产精品| 污视频网站在线观看免费|