第一步:创建项目,导入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实现

 

posted on 2019-04-20 16:30  风吹茶凉  阅读(299)  评论(0编辑  收藏  举报