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

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

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

    隨筆-21  評論-29  文章-0  trackbacks-0
    搭建與測試Spring的開發(fā)環(huán)境
    使用版本為Spring2.5.6

    新建一個Java Project 命名為spring 并導(dǎo)入相關(guān)的jar包
    配置Spring配置文件

    在src下新建beans.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.5.xsd"
    >
              
    </beans>

    實例化Spring容器 建議用方法一

    新建一個單元測試SpringTest,并導(dǎo)入測試所用的包
    package junit.test;
    import org.junit.BeforeClass;
    import org.junit.Test;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import cn.itcast.service.PersonService;

    public class SpringTest {

        @BeforeClass
        public static void setUpBeforeClass() throws Exception {
        }

        @Test public void instanceSpring(){
            ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
                }
    }

    新建一個業(yè)務(wù)Bean,命名為PersonServiceBean;抽取PersonServiceBean的接口。
    package cn.itcast.service.impl;

    import cn.itcast.service.PersonService;

    public class PersonServiceBean implements PersonService {

        
    public void save(){
            System.out.println(
    "我是save()方法");
        }

    }


    package cn.itcast.service;

    public interface PersonService {

        
    public void save();

    }
    在配置文件中加入如下語句實現(xiàn)
    <bean id="personService" class="cn.itcast.service.impl.PersonServiceBean"></bean>
    注意:編寫spring配置文件時,不能出現(xiàn)幫助信息 同通過如下方法解決


    修改SpringTest代碼
    package junit.test;
    import org.junit.BeforeClass;
    import org.junit.Test;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import cn.itcast.service.PersonService;

    public class SpringTest {

        @BeforeClass
        
    public static void setUpBeforeClass() throws Exception {
        }


        @Test 
    public void instanceSpring(){
            ApplicationContext ctx 
    = new ClassPathXmlApplicationContext("beans.xml");
            PersonService personService 
    = (PersonService)ctx.getBean("personService");
            personService.save();
        }

    }

    在實例化了容器之后,從容器中取得bean,再調(diào)用業(yè)務(wù)bean的save方法

    執(zhí)行SpringTest文件 觀察控制臺輸出



    以上證明本Spring程序運行成功!

    代碼參考 /Files/luckygino/spring.rar
    posted on 2009-05-06 10:25 特立獨行 閱讀(464) 評論(0)  編輯  收藏 所屬分類: Spring框架
    主站蜘蛛池模板: 四虎永久在线精品免费一区二区| 中文字幕亚洲色图| 337P日本欧洲亚洲大胆精品| 美女视频黄免费亚洲| 亚洲国产成人精品无码区在线网站| 3344永久在线观看视频免费首页 | 亚洲精品国产电影| 美女被免费视频网站| 亚洲精品A在线观看| 国产成人1024精品免费| 亚洲国产日韩在线视频| 国产成年无码久久久免费| 国产亚洲精品一品区99热| 美女视频黄的免费视频网页| 亚洲自偷自拍另类12p| 成年人网站免费视频| 中文字幕乱码亚洲无线三区| 手机看片久久国产免费| 久久久久久久国产免费看| 亚洲av一综合av一区| 国产日本一线在线观看免费| 亚洲欧美日韩中文高清www777| 在线永久免费观看黄网站| 国产免费AV片在线观看播放| 久久久久亚洲AV片无码| 最新猫咪www免费人成| 免费一区二区无码视频在线播放| 亚洲色爱图小说专区| 成人免费激情视频| 色偷偷亚洲第一综合| 亚洲av综合avav中文| 成人男女网18免费视频| 国产免费牲交视频免费播放| 老色鬼久久亚洲AV综合| 日本不卡免费新一二三区| 精品久久久久久无码免费| 亚洲第一页中文字幕| 免费人成激情视频| 久久国产精品免费看| 亚洲国产精品精华液| 亚洲av中文无码乱人伦在线咪咕|