一、打开网址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基础功能源码走读的环境