Benefits of Using the Spring Framework Dependency Injection 依赖注入 控制反转
小结:
1、
Dependency Injection is merely one concrete example of Inversion of Control.
依赖注入是仅仅是控制反转的一个具体例子。
2、
Dependency Injection helps in gluing these classes together and at the same time keeping them independent.
依赖注入既使类粘合又使类分离。
3、
For example, class A is dependent of class B. Now, let's look at the second part, injection. All this means is, class B will get injected into class A by the IoC.
A依赖B,B通过控制反转注入A。
Spring Framework Overview https://www.tutorialspoint.com/spring/spring_overview.htm
The core features of the Spring Framework can be used in developing any Java application, but there are extensions for building web applications on top of the Java EE platform. Spring framework targets to make J2EE development easier to use and promotes good programming practices by enabling a POJO-based programming model.
Benefits of Using the Spring Framework
Following is the list of few of the great benefits of using Spring Framework −
Spring enables developers to develop enterprise-class applications using POJOs. The benefit of using only POJOs is that you do not need an EJB container product such as an application server but you have the option of using only a robust servlet container such as Tomcat or some commercial product.
Spring is organized in a modular fashion. Even though the number of packages and classes are substantial, you have to worry only about the ones you need and ignore the rest.
Spring does not reinvent the wheel, instead it truly makes use of some of the existing technologies like several ORM frameworks, logging frameworks, JEE, Quartz and JDK timers, and other view technologies.
Testing an application written with Spring is simple because environment-dependent code is moved into this framework. Furthermore, by using JavaBeanstyle POJOs, it becomes easier to use dependency injection for injecting test data.
Spring's web framework is a well-designed web MVC framework, which provides a great alternative to web frameworks such as Struts or other over-engineered or less popular web frameworks.
Spring provides a convenient API to translate technology-specific exceptions (thrown by JDBC, Hibernate, or JDO, for example) into consistent, unchecked exceptions.
Lightweight IoC containers tend to be lightweight, especially when compared to EJB containers, for example. This is beneficial for developing and deploying applications on computers with limited memory and CPU resources.
Spring provides a consistent transaction management interface that can scale down to a local transaction (using a single database, for example) and scale up to global transactions (using JTA, for example).
不重新发明轮子
Dependency Injection (DI)
The technology that Spring is most identified with is the Dependency Injection (DI) flavor of Inversion of Control. The Inversion of Control (IoC) is a general concept, and it can be expressed in many different ways. Dependency Injection is merely one concrete example of Inversion of Control.
When writing a complex Java application, application classes should be as independent as possible of other Java classes to increase the possibility to reuse these classes and to test them independently of other classes while unit testing. Dependency Injection helps in gluing these classes together and at the same time keeping them independent.
What is dependency injection exactly? Let's look at these two words separately. Here the dependency part translates into an association between two classes. For example, class A is dependent of class B. Now, let's look at the second part, injection. All this means is, class B will get injected into class A by the IoC.
Dependency injection can happen in the way of passing parameters to the constructor or by post-construction using setter methods. As Dependency Injection is the heart of Spring Framework, we will explain this concept in a separate chapter with relevant example.
依赖注入 植入
将2个类粘合同时保证各自的独立性
通过控制反转,一个类被注入到另一个类
Benefits of Using the Spring Framework Dependency Injection 依赖注入 控制反转的更多相关文章
- Spring进阶之路(1)-Spring核心机制:依赖注入/控制反转
原文地址:http://blog.csdn.net/wangyang1354/article/details/50757098 我们经常会遇到这样一种情景,就是在我们开发项目的时候经常会在一个类中调用 ...
- spring in action学习笔记一:DI(Dependency Injection)依赖注入之CI(Constructor Injection)构造器注入
一:这里先说一下DI(Dependency Injection)依赖注入有种表现形式:一种是CI(Constructor Injection)构造方法注入,另一种是SI(Set Injection) ...
- Helloworld之Spring依赖注入/控制反转(DI/IoC)版
Helloworld之Spring依赖注入/控制反转(DI/IoC)版 作者:雨水, 日期:2014-10-29 摘要:本文主要用于培训刚開始学习的人理解Spring中的依赖注入的基本概念. 先介绍依 ...
- Spring框架xml配置文件 复杂类型属性注入——数组 list map properties DI dependency injection 依赖注入——属性值的注入依赖于建立的对象(堆空间)
Person类中的各种属性写法如下: package com.swift.person; import java.util.Arrays; import java.util.List; import ...
- asp.net core 系列之Dependency injection(依赖注入)
这篇文章主要讲解asp.net core 依赖注入的一些内容. ASP.NET Core支持依赖注入.这是一种在类和其依赖之间实现控制反转的一种技术(IOC). 一.依赖注入概述 1.原始的代码 依赖 ...
- Spring4 -03 -Dependency Injection (依赖注入) : 代码体现/配置xml/测试
DI:中文名称:依赖注入 英文名称((Dependency Injection) DI 是什么? 3.1 DI 和IoC 是一样的,差不多一样的技术和模板! 3.2 当一个类(A)中需要依赖另一个类( ...
- Spring 依赖注入控制反转实现,及编码解析(自制容器)
定义: 在运行期,由外部容器动态的将依赖对象动态地注入到组件中. 两种方式: 手工装配 -set方式 -构造器 -注解方式 自动装配(不推荐) 1利用构造器 2set方法注入 dao: package ...
- 基于注解的DI(DI:Dependency Injection 依赖注入)
注解方式xml里面就不需要注册bean了. 构建注解需要 1.导入spring-aop-4.2.1.RELEASE.jar 包 2.需要更换配置文件头,即添加相应的约束. 现在的Student类就要 ...
- Spring.NET 的IOC(依赖注入)
(1) ioc,意思是Inversion of control,(反转控制),控制反转,就是交换控制权的意思.现在一般不使用这个词,一般使用dependency injection(依赖注入).依赖 ...
随机推荐
- MJRefresh原理分析
MJRefresh是流行的下拉刷新控件.前段时间为了修复一个BUG.读了它的源代码.本文总结一下实现的原理 下拉刷新的基本原理 大部分的下拉刷新控件.都是用contentInset实现的.默认情况下. ...
- Erlang的Web库和框架
ChicagoBoss,Nitrogen ,Zotontic,BeepBeep,ErlyWeb,Erlang Boss. 转自:http://bbs.chinaunix.net/thread-3764 ...
- 一个不错的在线的js调试器
一个不错的在线的js调试器,可见即可得: http://jsbin.com/
- tomcat日志神器--kibana
最近公司搭了套kibana的日志系统,感受比原来查看日志方便多了.记得以前查看日志是通过ssh到服务器,查看系统日志用vi查看器查看或者下载到本地,用logview查看搜索,可读性很低.自从用了kib ...
- MongoDB基础入门视频教程
MongoDB基础入门视频教程http://www.icoolxue.com/album/show/98
- db2 over()
说起 DB2 在线分析处理,可以用很好很强大来形容.这项功能特别适用于各种统计查询,这些查询用通常的SQL很难实现,或者根本就无发实现.首先,我们从一个简单的例子开始,来一步一步揭开它神秘的面纱,请看 ...
- 在loadrunner中使用winsocket协议编写脚步三部曲
这两天写了一个winsocket的脚本,没有通过录制的方式,是直接手写的.下面贴出来和大家分享: 脚本的写法很简单,大体说来,就像把大象放进冰箱一样,总共分三步: 第一步:把冰箱门打开. //建立到服 ...
- jdbcType 与 Java type
JDBC Type Java Type CHAR String VARCHAR String LONGVARCHAR ...
- MathType出现乱码公式怎么恢复
在我们平时使用word上的数学公式编辑器的时候,有时一些公式会出现乱码的问题.这个时候可以改为使用MathType时,那么MathType出现乱码公式怎么恢复呢?如果只是少量公式可以手动重新输入,如果 ...
- Entity FrameWork实现增、删、改、分页的数据层代码实现
public bool AddEntity(Customer entity)//添加实体 { MyHotelModelContainer hotelDB = new MyHotelMo ...