zoukankan      html  css  js  c++  java
  • 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个类粘合同时保证各自的独立性

    通过控制反转,一个类被注入到另一个类

  • 相关阅读:
    Entity Framework6 with Oracle(可实现code first)
    ORACLE官方全托管驱动 Oracle.ManagedDataAccess 12.1.0.1.0
    C#连接Oracle数据库的四种方法
    WPF的TextBox产生内存泄露的情况
    ArcGIS客户端API中加载大量数据的几种解决办法(以Silverlight API为例)
    ArcGISDynamicMapServiceLayer 和 ArcGISTiledMapServiceLayer 区别
    ArcGIS客户端API中加载大量数据的几种解决办法
    MVVM中间接使用事件(命令)
    Tornaod框架
    跨站请求伪造CSRF
  • 原文地址:https://www.cnblogs.com/rsapaper/p/10036691.html
Copyright © 2011-2022 走看看