IoC控制反转--管理Bean

一、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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值