第一步:创建项目,导入jar包(只需要导入Spring的四个核心包和common-logging日志包即可)
|
第二步:创建一个普通的类UserService:
|
第三步:创建Spring配置文件:
Spring使用的xsd规则文件,对应spring-beans*.xsd,在Spring解压包schema/beans
目录下。
|
Eclipse配置xsd规则文件步骤:
|
注意:Schema location的key,在spring-beans、-4.3.16.RELEASE.jar的解压路劲下的meta-inf/spring.schema文件中可以找到。
配置路劲的时候,去掉http后面的反斜杠。
|
创建applicationContext.xml文件(在src目录创建即可)
(1)创建一个xml文件,选择spring-beans规则文件模板
|
|
(3)配置applicationContext.xml文件,将UserService放入spring容器中。
|
创建一个测试类UserServiseTEST
|
5.spring容器的两个实现
|
(1)ClasspathXmlApplicationContenxt从classpath路径中加载xml文件
|
(2)FileSystemXmlApplicationContext从文件系统中加载xml文件,基于io实现
|