<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的開發環境
    使用版本為Spring2.5.6

    新建一個Java Project 命名為spring 并導入相關的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,并導入測試所用的包
    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");
                }
    }

    新建一個業務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();

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


    修改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,再調用業務bean的save方法

    執行SpringTest文件 觀察控制臺輸出



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

    代碼參考 /Files/luckygino/spring.rar
    posted on 2009-05-06 10:25 特立獨行 閱讀(465) 評論(0)  編輯  收藏 所屬分類: Spring框架
    主站蜘蛛池模板: 美女扒开屁股让男人桶爽免费| 99国产精品免费观看视频| 在线看片韩国免费人成视频| 亚洲精品国产精品国自产观看 | 无码精品国产一区二区三区免费| 亚洲w码欧洲s码免费| 亚洲国产高清视频在线观看| 亚洲综合色婷婷七月丁香| 最新亚洲人成无码网站| 女人毛片a级大学毛片免费| 亚洲最大成人网色| 四虎国产成人永久精品免费| 亚洲乱码中文字幕综合 | 免费观看无遮挡www的小视频| 亚洲AV美女一区二区三区| 在线观看免费国产视频| 日韩亚洲国产二区| 理论秋霞在线看免费| 亚洲国产精品无码久久| 精品国产免费一区二区| 亚洲国产综合精品中文第一| 国产免费看JIZZ视频| 亚洲国产日韩视频观看| 毛片免费全部播放一级| 亚洲综合一区二区三区四区五区| 国产免费不卡视频| 99亚洲精品高清一二区| 精品亚洲永久免费精品| 亚洲毛片αv无线播放一区| 久久精品国产亚洲av麻豆| 亚洲色最新高清av网站| 亚洲av日韩专区在线观看| 亚洲精品线路一在线观看| 久久99免费视频| 中文字幕无码亚洲欧洲日韩| 亚洲第一页日韩专区| 99热免费在线观看| 免费无码国产在线观国内自拍中文字幕 | 成人免费一区二区三区在线观看| 日本精品人妻无码免费大全 | 亚洲另类小说图片|