小结:

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 依赖注入 控制反转的更多相关文章

  1. Spring进阶之路(1)-Spring核心机制:依赖注入/控制反转

    原文地址:http://blog.csdn.net/wangyang1354/article/details/50757098 我们经常会遇到这样一种情景,就是在我们开发项目的时候经常会在一个类中调用 ...

  2. spring in action学习笔记一:DI(Dependency Injection)依赖注入之CI(Constructor Injection)构造器注入

    一:这里先说一下DI(Dependency Injection)依赖注入有种表现形式:一种是CI(Constructor Injection)构造方法注入,另一种是SI(Set Injection) ...

  3. Helloworld之Spring依赖注入/控制反转(DI/IoC)版

    Helloworld之Spring依赖注入/控制反转(DI/IoC)版 作者:雨水, 日期:2014-10-29 摘要:本文主要用于培训刚開始学习的人理解Spring中的依赖注入的基本概念. 先介绍依 ...

  4. Spring框架xml配置文件 复杂类型属性注入——数组 list map properties DI dependency injection 依赖注入——属性值的注入依赖于建立的对象(堆空间)

    Person类中的各种属性写法如下: package com.swift.person; import java.util.Arrays; import java.util.List; import ...

  5. asp.net core 系列之Dependency injection(依赖注入)

    这篇文章主要讲解asp.net core 依赖注入的一些内容. ASP.NET Core支持依赖注入.这是一种在类和其依赖之间实现控制反转的一种技术(IOC). 一.依赖注入概述 1.原始的代码 依赖 ...

  6. Spring4 -03 -Dependency Injection (依赖注入) : 代码体现/配置xml/测试

    DI:中文名称:依赖注入 英文名称((Dependency Injection) DI 是什么? 3.1 DI 和IoC 是一样的,差不多一样的技术和模板! 3.2 当一个类(A)中需要依赖另一个类( ...

  7. Spring 依赖注入控制反转实现,及编码解析(自制容器)

    定义: 在运行期,由外部容器动态的将依赖对象动态地注入到组件中. 两种方式: 手工装配 -set方式 -构造器 -注解方式 自动装配(不推荐) 1利用构造器 2set方法注入 dao: package ...

  8. 基于注解的DI(DI:Dependency Injection 依赖注入)

    注解方式xml里面就不需要注册bean了. 构建注解需要 1.导入spring-aop-4.2.1.RELEASE.jar 包  2.需要更换配置文件头,即添加相应的约束. 现在的Student类就要 ...

  9. Spring.NET 的IOC(依赖注入)

    (1)  ioc,意思是Inversion of control,(反转控制),控制反转,就是交换控制权的意思.现在一般不使用这个词,一般使用dependency injection(依赖注入).依赖 ...

随机推荐

  1. CentOS下rpm指令和yum指令详解

    centos的软件安装大致可以分为两种类型: [centos]rpm文件安装,使用rpm指令 类似[ubuntu]deb文件安装,使用dpkg指令 [centos]yum安装 类似[ubuntu]ap ...

  2. jquery validate自定义规则

    //检查身份证号码是否存在 $.validator.addMethod("checkIDCardExist", function (value, element) { if ($( ...

  3. Ubuntu 10.04 安装 Oracle11gR2

    注意点: 在 ubuntu的 /bin 下建立以下几个基本命令的链接: /bin/basename->/usr/bin/basename /bin/awk->/usr/bin/gawk / ...

  4. MathType给公式底部加箭头的教程

    箭头符号在数学中很常用的一个符号了,不管是在推导过程用以表示逻辑关系,还是表示向量,箭头符号都起着它就的作用.我们经常习惯给公式或者字母的上部加上箭头,那如何给公式的底部加上箭头呢?下面来介绍word ...

  5. 【Matlab】运动目标检测之“帧差法”

    videoObj = VideoReader('4.avi');%读视频文件 nframes = get(videoObj, 'NumberOfFrames');%获取视频文件帧个数 : nframe ...

  6. zoj 1022 - Parallel Expectations

    题目:有两个指令序列,在执行时,能够执行随意指令序列的下一条指令.每条指令要一直执行到结束. 求两组指令执行结束后,每一个变量里面存储值的期望. 分析:dp,模拟.这道题算不上难题,只是算得上的麻烦题 ...

  7. PHP - PhpStorm 快捷键大全 PhpStorm 常用快捷键和配置(转)

    原文地址:http://www.cr173.com/html/66775_1.html PhpStorm 是 JetBrains 公司开发的一款商业的 PHP 集成开发工具,PhpStorm可随时帮助 ...

  8. 常用hive的CLI命令

    1.show tables  --查看所有表 2.desc tabname --查看表信息 3.dfs -ls 目录  查看hdfs上面的文件  dfs -lsr /user  递归显示目录/user ...

  9. 从spring容器中取出注入的bean

    从spring容器中取出注入的bean 工具类,代码如下: package com.hyzn.fw.util; import org.springframework.beans.BeansExcept ...

  10. linux--GCC用法

    1简介 2简单编译 2.1预处理 2.2编译为汇编代码(Compilation) 2.3汇编(Assembly) 2.4连接(Linking) 3多个程序文件的编译 4检错 5库文件连接 5.1编译成 ...