Spring框架

第一步:创建项目,导入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规则文件模板

 

 (2)选择生成文件属性

 

 

(3)配置applicationContext.xml文件,将UserService放入spring容器中。

 

第四步:从spring容器获取对象

创建一个测试类UserServiseTEST

 

 5.spring容器的两个实现

 

(1)ClasspathXmlApplicationContenxt从classpath路径中加载xml文件

 

(2)FileSystemXmlApplicationContext从文件系统中加载xml文件,基于io实现

 

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念