主要内容:

Dependency Injection

The concept of dependency injection (DI), objects are given their dependencies at construction time, is one of the foundations of the Spring Framework. You have also probably heard of Inversion of Control (IoC). IoC is a broader, more general concept that can be addressed in different ways. IoC lets developers decouple and focus on what is important for a given part of an enterprise application, but without having to think about what other parts of the system do. Programming to interfaces is one way to think about decoupling.

Almost every enterprise application consists of multiple components that need to work together. In the early days of Java enterprise development, we simply put all the logic of constructing those objects (and the objects those objects needed) in the constructor (see Listing 2-1). At first sight, there is nothing wrong with that approach; however, as time progressed, object construction became slow, and objects had a lot of knowledge they shouldn’t have had (see the Single Responsibility Principle). Those classes became hard to maintain, and they were also quite hard to unit and/or integration test.

The class from Listing 2-1 programs to interfaces, but it still needs to know about the concrete implementation of an interface simply to do object construction. Applying IoC by decoupling the construction logic (collaborating objects) makes the application easier to maintain and increases testability. There are seven ways to decouple this dependency construction logic:

1. Factory pattern

2. Service locator pattern

3. Dependency injection

a. Constructor based

b. Setter based

c. Interface based

d. Annotation driven

4. Contextualized lookup

When using the factory pattern, service locator pattern, or contextualized lookup, the class that needs the dependencies still has some knowledge about how to obtain the dependencies. This can make things easier to maintain, but it can still be hard to test. Listing 2-2 shows a contextualized lookup from JNDI (Java Naming and Directory Interface). The constructor code would need to know how to do the lookup and handle exceptions.

The immediately preceding code isn’t particularly clean; for example, imagine if there were multiple dependencies from different contexts. The code would quickly become messy and increasingly hard, if not impossible, to unit test (see Chapter 9 for more information on testing).

java外文文献_spring框架外文文献 PDF 下载相关推荐

  1. java中间件源码_《Java中间件技术及其应用开发》PDF下载

    资源名称:<Java中间件技术及其应用开发>PDF 下载 < 内容简介······ 本书使用丰富的案例介绍了使用Java技术进行中间件编程的方法及技巧,包括JSP.Java serV ...

  2. java框架外文翻译_Spring框架-毕业论文外文文献翻译.doc

    黑龙江工程学院本科生毕业设计 外文文献翻译 SpringFramework Spring is an open source framework, and Spring was launched in ...

  3. 高级java知识结构图,Spring高级框架课程笔记 PDF 下载

    主要内容: Spring ⾼级框架(讲师:应癫) ssh = spring + struts + hibernate ssm = spring + springmvc + mybatis spring ...

  4. java四大模块_Spring框架七大模块

    核心容器(Spring Core) 核心容器提供Spring框架的基本功能.Spring以bean的方式组织和管理Java应用中的各个组件及其关系.Spring使用BeanFactory来产生和管理B ...

  5. java具名参数_Spring框架笔记(二十五)——NamedParameterJdbcTemplate与具名参数

    在经典的 JDBC 用法中, SQL 参数是用占位符 ? 表示,并且受到位置的限制. 定位参数的问题在于, 一旦参数的顺序发生变化, 就必须改变参数绑定. 在 Spring JDBC 框架中, 绑定 ...

  6. java 事件类型_Spring框架中有哪些不同类型的事件?

    Spring内置事件 内置事件中由系统内部进行发布,只需注入监听器 自定义事件 事件类需要继承ApplicationEvent,代码如下: public class BigEvent extends ...

  7. java重新定义_重新定义Spring Cloud实战 PDF 下载

    资料目录: 前言 第1章 微服务与SpringCloud1 1.1 微服务架构概述1 1.1.1 应用架构的发展1 1.1.2 微服务架构3 1.1.3 微服务解决方案4 1.2 Spring Clo ...

  8. java基础与案例开发详解 pdf下载_Java基础与案例开发详解(张孝祥) pdf_IT教程网...

    资源名称:Java基础与案例开发详解(张孝祥) pdf 第1.2和3章介绍Java环境的安装配置,Java程序的开发过程和Java语言的基础语法. 第4章介绍数组和常用算法的相关知识. 第5章和6章介 ...

  9. 多线程面试题_100多线程和Java并发面试问答–最终清单(PDF下载)

    多线程面试题 在这篇文章中,我们将提供有关多线程和Java并发面试问答的综合文章. 编者注:并发始终是开发人员的挑战,编写并发程序可能非常困难. 引入并发时,有很多事情可能会崩溃,并且系统的复杂性会大 ...

  10. Java 8功能教程– ULTIMATE指南(PDF下载)

    编者注:在本文中,我们提供了全面的Java 8功能教程. 自Java 8公开发布以来已经有一段时间了,所有迹象都表明这是一个非常重要的版本. 我们在Java Code Geeks处提供了大量教程,例如 ...

最新文章

  1. 【PHPWord】TitleTOC
  2. C#全局键盘监听(Hook)
  3. [Android] 任意时刻从子线程切换到主线程的实现
  4. iOS cocos2d 2游戏开发实战(第3版)---你的第一个游戏!
  5. 【C++】Visual Studio教程(十) - 初步了解 Visual Studio IDE
  6. 分区和分片的区别_PHP: 分区和分片 - Manual
  7. linux grub 下载,GRUB 2.04发布下载,附新功能介绍
  8. python 到 poc
  9. javascript 布尔类型
  10. OSGI嵌入tomcat应用服务器(gem-web)——资源下载
  11. MacOS怎样启用悬停文本功能的具体操作方法!
  12. Python天天学_03_基础三
  13. 【论文解读】[目标检测]retinanet
  14. mysql时间10位数字_mysql—MySQL数据库中10位时间戳转换为标准时间后,如何对标准时间进行加减X天处理...
  15. Struts原理、开发及项目实施
  16. dw中css制作导航,Dreamweaver导航条按钮制作方法
  17. 工程师笔记 | 嵌入式工程师常用软件
  18. 【方案分享】2022虎年新春潮玩嘉年华活动策划方案:我们超虎的.pptx(附下载链接)...
  19. nginx 配置后缀
  20. 8421码,5421码,2421码,余3码的区别

热门文章

  1. ie11不兼容java_解决ie11不兼容的多个方法
  2. 手游方舟怎么输入代码_方舟秘籍代码详细攻略介绍一览
  3. JavaScript打开新窗口的方法
  4. 基于Ace Admin 的菜单栏实现
  5. visual studio-wdk8.1+vs2013中使用winusb模版开发usb设备驱动
  6. 微信公众平台开发进阶篇资源集锦
  7. 微信公众号制作简单线上预约系统,公众号预约系统怎么做
  8. Android中的armeabi等如何适配
  9. Python代码自动转成C++代码
  10. 车林通购车之家--购车计算器模块--算法js