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(依赖注入).依赖 ...
随机推荐
- The request lifetime scope cannot be created because the HttpContext is not available
项目中应用了Autofac,在Global轮询处理Job的时候,需要获取现有得Service,而这些Service已经通过Autofac进行了配置,所以理所应当的用下面的代码去获取了. Depende ...
- Openstack镜像和密码
#!/bin/sh passwd ubuntu<<EOF ubuntu ubuntu EOF sed -i 's/PasswordAuthentication no/PasswordAut ...
- MySQL数据库行去重复
1.创立数据表
- notepadd添加插件
markdown相关插件: https://www.cnblogs.com/tocy/p/npp-support-markdonw-extension.html
- Spring-JDBC配置
以C3P0连接池为例:由于C3P0是第三方,我们无法使用注解将其定义为bean,因此需要在applicationContext.xml中配置: <!-- 导入配置文件 --> <co ...
- Js注释和对象
1.注释 单行: //注释内容 console.log('加油~');//在控制台输出一条信息: 多行: /*注释内容*/: 2.对象 1)对象是一个复合值,是根据某种引用类型创建出来的实例. 2)常 ...
- Ubuntu 安装 Oracle11gR2:'install' of makefile '/home/oracle/app/oracle/product/11.2.0/dbhome_1/ctx/lib/ins_ctx.mk'
网上包括官方,就是教给你如何安装依赖包什么的:libstdc++5,但很麻烦:既要下载找相关的包,还不一定能安装的上. 其实,仅仅是为了安装,直接从二进制的deb包里,解压一个 “libstdc++. ...
- CS文件类头注释
1.修改unity生成CS文件的模板(模板位置:Unity\Editor\Data\Resources\ScriptTemplates 文件名:81-C# Script-NewBehaviourScr ...
- 公式编辑器编辑倒L符号的方法
数学公式全都是由数字字母和一些符号组成的,一些常用的字母符号我们使用起来也很熟练,但是在数学中也有一些符号是比较少用的,比如倒着的L,这个符号在一些函数中出现过,表示某一类的函数.在word公式编辑器 ...
- mongoDB的shell数组操作器
http://www.2cto.com/database/201304/205024.html mongoDB数组操作器 $push会向数组末尾加入一个元素,如果数组不存在,则会创建这个数组. 增 ...