<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框架
    主站蜘蛛池模板: 亚洲国产综合自在线另类| 日本免费人成网ww555在线| 羞羞漫画在线成人漫画阅读免费| 亚洲五月午夜免费在线视频| 亚洲人成在线免费观看| 国产jizzjizz免费视频| 久久久久亚洲AV无码专区体验| 亚洲av第一网站久章草| 免费人妻无码不卡中文字幕系| 免费人成在线观看网站视频| 亚洲自偷精品视频自拍| 久久免费视频一区| 日本高清免费中文字幕不卡| 亚洲欧洲日产专区| 在线永久免费的视频草莓| 国产A在亚洲线播放| 亚洲精品色在线网站| 日本免费网址大全在线观看| 亚洲av无码不卡一区二区三区| 国产天堂亚洲国产碰碰| 69堂人成无码免费视频果冻传媒 | 久久99精品免费一区二区| 中文字幕不卡亚洲| 日本视频免费观看| 日韩精品成人亚洲专区| 亚洲国产精品成人精品小说| 岛国av无码免费无禁网站| 亚洲狠狠狠一区二区三区| 四虎影视在线影院在线观看免费视频| 亚洲伊人久久综合中文成人网| 香港特级三A毛片免费观看| 国产av无码专区亚洲av桃花庵| 日本视频一区在线观看免费| 亚洲av永久无码精品秋霞电影秋| 国产精品亚洲高清一区二区| 9420免费高清在线视频| 666精品国产精品亚洲| 国产成人在线观看免费网站| 99亚洲乱人伦aⅴ精品| 精品亚洲综合在线第一区| 免费无码A片一区二三区|