一、打開網址http://repo.spring.iojava
二、點擊菜單Artifactory,以下圖spring
3,輸入「spring-framework-4.1.5」進行搜索、express
4,在搜索列表中選擇標記的包進行下載(該包中包含jar,源代碼,以及說明文檔)app
五、新建一Web project項目,將spring-framework-4.1.5.RELEASE-dist\spring-framework-4.1.5.RELEASE\libs中的一下jar導入到項目中測試
spring-beans-4.1.5.RELEASE.jar
spring-core-4.1.5.RELEASE.jar
spring-expression-4.1.5.RELEASE.jar
spring-context-4.1.5.RELEASE.jar
commons-logging-1.0.4.jarcode
6,將以上spring相關jar關聯上spring-framework-4.1.5.RELEASE-dist\spring-framework-4.1.5.RELEASE\libs下的源碼包xml
七、在src目錄下車間一xml文件,命名爲applicationContext.xml,其內容爲文檔
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> <beans> <bean id="studentBean" class="com.bean.StudentBean"></bean> </beans>
8,建立Beanget
package com.bean; public class StudentBean { public void showInfo(String name,String No) { System.out.println("你的名字是:" + name +",你的學號是:"+No); } }
9,建立測試類源碼
package com.test; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.ClassPathResource; import com.bean.StudentBean; public class MyTest { public static void main(String[] args) { ClassPathResource res = new ClassPathResource("/applicationContext.xml"); BeanFactory bf = new XmlBeanFactory(res); StudentBean bean = (StudentBean)bf.getBean("studentBean"); bean.showInfo("yangay","123456"); } }
10,運行結果爲:
你的名字是:yangay,你的學號是:123456
以上10個步驟搭建好進行Spring基礎功能源碼走讀的環境