一、建立一个web工程
二、总共需要导入两个包的内容
1、spring-framwork-4.2.4.RELEASE-dist.zip(spring自己的包)
2、spring相关依赖包
本文需要:
libs中的beans、core、context、expression
注意:spring框架在运行时还会找一个日志包:commons-logging.jar(必须导入)
企业开发需要使用日志包:apache-log4j.jar
以上两个全都导入
3、在src下面新建一个配置文件applicationContext.xml(建议使用applicationContext这个名字)
写入文件的所有约束,所有约束被抽出来放在一个html文件中(文件位置:spring-framwork-4.2.4.RELEASE-dist.zip-docs-spring-framework-reference--html--xsd- configuration.html--复制40.2.12the beans schema中的<beans></beans>中的代码放入applicationContext.xml)
注意:约束网址为:http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
注意:上述约束会有一个网址,是在网上找到的,需要导入本地约束。实际上咱们本地jar包中有约束(位置:spring-framwork-4.2.4.RELEASE--schema--beans--spring- beans-4.2.xsd)。
window--preference--查找XML Catalog--点击ADD--key中放入网络约束地址http://www.springframework.org/schema/beans/spring-beans.xsd;location对应本地约束的实 际地址spring-framwork-4.2.4.RELEASE--schema--beans--spring- beans-4.2.xsd--点击OK--------此时导入了本地约束条件。
代码功能实现:
代码1:
1、创建一个接口类Car
2、创建一个实现类CarImpl
3、创建一个实现类CarTest
代码2:
1、创建一个接口类Person
2、创建一个实现类PersonImpl
3、创建一个测试类UserTest
以上两个验证spring IOC的代码,都需要在applicationContext.xml中进行配置