您的位置:首页 > 编程语言 > Java开发

spring中的命名空间

2015-06-09 15:34 471 查看
一、IoC 概述 

IoC(控制反转:Inverse of Control)是Spring 容器的核心,与DI(依赖注入:Dependency Injection)是同一个意思。

从注入方法上看,主要可以划分为三种类型:构造函数注入、属性注入和接口注入。Spring 支持构造函数注入和属性注入。

构造函数注入

在构造函数注入中,我们通过调用类的构造函数,将接口实现类通过构造函数变量传入。由于是构造函数,就必须注入,没有选择性。

属性注入

属性注入可以有选择地通过Setter 方法完成调用类所需依赖的注入,更加灵活方便。

接口注入

将调用类所有依赖注入的方法抽取到一个接口中,调用类通过实现该接口提供相应的

注入方法。为了采取接口注入的方式,必须先声明一个接口,由于通过接口注入需要额外声明一个接口,增加了类的数目,而且它的效果和属性注

入并无本质区别。

 

二、Spring 3的命名空间

 

可以访问:http://www.springframework.org/schema/

查看所有的schema文件,和对应的命名空间。

常用的命名空间如下:

 

spring-beans-3.0.xsd 最主要的命名空间,也是默认命名空间,用于配置Bean。
http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
 

简化属性配置

p命名空间,设置属性值的格式为 p:属性名="值"
http://www.springframework.org/schema/p 
(由于属性名是可变的,所以没有对应的Schema文件)

 

spring-tx-3.1.xsd 声明式事务配置
http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
 

spring-context-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
 

spring-mvc-3.0.xsd Spring MVC的配置
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
 

spring-aop-3.0.xsd AOP的配置
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
 

spring-util-3.1.xsd 简化某些复杂的标准配置
http://www.springframework.org/schema/util  http://www.springframework.org/schema/util/spring-util-3.1.xsd
 

spring-jdbc-3.1.xsd Spring内嵌数据库的配置
http://www.springframework.org/schema/jdbc  http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
spring-jee-3.1.xsd 为了简化EJB,JDNI提供的
http://www.springframework.org/schema/jee  http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
 

spring-jpa.xsd jpa配置
http://www.springframework.org/schema/data/jpa  http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
 

spring-jms-3.0.xsd JMS配置
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
 

spring-lang-3.0.xsd JRuby,Groovy动态语言配置
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
 

spring-oxm-3.0.xsd 配置对象XML映射
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
 

spring-task-3.0.xsd 任务调度
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
 

spring-tool-3.0.xsd 可集成Spring一些有用的工具
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-3.0.xsd
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: