下载架包
这里以4.3.20版本为例,点击下载:SpringFramewoek 4.3.20版本
解压缩后目录:

— docs目录为api和开发文档介绍,schema目录为配置xml的schema约束文件,libs文件夹中为我们要使用的架包

注意:另外还要下载spring的依赖架包: commons-logging
安装
1. 打开IDE工具,新建项目,导入上文下载好的架包

2. 创建实体类并意添加一个方法打印输入
1 2 3 4 5 6 7 8 9
| package cn.sr.spring;
public class User {
public void isSelf() { System.out.println("我是谁,我在哪,我在干什么"); }
}
|
3. 在src目录下 创建xml文件
1 2 3 4 5 6 7 8
| <?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.xsd"> <bean id="user" class="cn.sr.spring.User"></bean> </beans>
|
4. 创建测试类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| package cn.sr.spring; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.junit.*;
public class TestBean {
@Test public void test() { ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); User user = (User) context.getBean("user"); System.out.println(user); user.isSelf(); }
}
|
配置完成

如图所示,即配置成功。