Dependency Injection 依赖注入,在Spring框架负责创建Bean对象时,动态的将依赖对象注入到Bean组件。

1.在UserService中提供一个get/set的name方法,在beans.xml中通过property去注入

2.配置bean xml文件

3,创建测试类,调用service 方法

本次测试类采用的是最常用的ClassPathXmlApplicationContext 加载

加载spring容器有三种方式

类路径加载  ApplicationContext context =

new ClassPathXmlApplicationContext("com/zz/spring/demo01/beans.xml");

文件系统路径加载

使用bean工厂加载

Ø  BeanFactory 采取延迟加载,第一次getBean时才会初始化Bean

Ø  ApplicationContext是对BeanFactory扩展,提供了更多功能

l  国际化处理

l  事件传递

l  Bean自动装配

l  各种不同应用层的Context实现

测试通过    创建UserService对象控制权被反转到了Spring框架(ioc)

ApplicationContext context =

new ClassPathXmlApplicationContext("com/gyf/spring/demo01/beans.xml");

.4BeanFactory和ApplicationContext对比

Ø  BeanFactory 采取延迟加载,第一次getBean时才会初始化Bean

Ø  ApplicationContext是对BeanFactory扩展,提供了更多功能

l  国际化处理

l  事件传递

l  Bean自动装配

l  各种不同应用层的Context实现

Spring Dependency Injection浅析的更多相关文章

  1. Spring点滴七:Spring中依赖注入(Dependency Injection:DI)

    Spring机制中主要有两种依赖注入:Constructor-based Dependency Injection(基于构造方法依赖注入) 和 Setter-based Dependency Inje ...

  2. Benefits of Using the Spring Framework Dependency Injection 依赖注入 控制反转

    小结: 1. Dependency Injection is merely one concrete example of Inversion of Control. 依赖注入是仅仅是控制反转的一个具 ...

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

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

  4. [转载][翻译] IoC 容器和 Dependency Injection 模式

    原文地址:Inversion of Control Containers and the Dependency Injection pattern 中文翻译版本是网上的PDF文档,发布在这里仅为方便查 ...

  5. Inversion of Control Containers and the Dependency Injection pattern(转)

    In the Java community there's been a rush of lightweight containers that help to assemble components ...

  6. 【译】Dependency Injection with Autofac

    先说下为什么翻译这篇文章,既定的方向是架构,然后为了学习架构就去学习一些架构模式.设计思想. 突然有一天发现依赖注入这种技能.为了使得架构可测试.易维护.可扩展,需要架构设计为松耦合类型,简单的说也就 ...

  7. 黄聪:Microsoft Enterprise Library 5.0 系列教程(八) Unity Dependency Injection and Interception

    原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(八) Unity Dependency Injection and Interception 依赖注入容器Uni ...

  8. Srping - bean的依赖注入(Dependency injection)

    目录 1 概述 2 两种基本的依赖注入方式 2.1 构造函数方式 2.2Setter方式 3 其他依赖注入功能 3.1 <ref/>标签引用不同范围的bean 3.2 内部bean 3.3 ...

  9. Inversion of Control Containers and the Dependency Injection pattern

    https://martinfowler.com/articles/injection.html One of the entertaining things about the enterprise ...

随机推荐

  1. 自学linux——6.安全外壳协议(ssh服务)

    ssh服务 ssh(secure shell)安全外壳协议:远程连接协议,远程文件传输协议 1.协议使用端口号默认:22 若要修改,则修改ssh服务的配置文件/etc/ssh/ssh_config a ...

  2. azure bash: kubectl: command not found

    [root@***]# az aks install-cliDownloading client to "/usr/local/bin/kubectl" from "ht ...

  3. Vue-Promise

    promise 就是一种异步编程的的解决方案 当执行网络请求的时候,代码就会出现阻塞,下面的代码要等待请求完成了在运行,所以我们一般网络请求的时候就去开启一个异步任务,一边请求一边执行其他代码 请求到 ...

  4. 常见的嵌入式linux学习和如何选择ARM芯片问答

    常见的ARM嵌入式学习问答,设计者和学习者最关心的11个问题: 1.          ARM嵌入式是学习硬件好还是学习软件好? 2.          嵌入式软件和硬件,哪一种职位待遇更高?或者说, ...

  5. [编译] 9、在Linux下搭建 nordic 最新基于 zephyr 的开发烧写环境

    目录 前言 1.概述 2.安装工具 3.获取 nRF Connect SDK 源码 4.安装 Python modules 5.安装 toolchain 6.下载 nRF Command Line T ...

  6. 精简ABP的模块依赖

    ABP的模块非常方便我们扩展自己的或使用ABP提供的模块功能,对于ABP自身提供的模块间的依赖关系想一探究竟,并且试着把不必要的模块拆掉,找到那部分核心模块.本次使用的是AspNetBoilerpla ...

  7. SQL 练习15

    检索" 01 "课程分数小于 60,按分数降序排列的学生信息 SELECT Student.* ,SC.score from Student,SC WHERE sc.cid = ' ...

  8. noip17

    复杂度分析全部摘自题解 T1 sb优化暴力 暴力20-40pts,我只拿了20pts. 正解: bitset 优化暴力,但是会MLE. 再次考虑如何优化,我们统计一下每个点的入度,每次遍历到这个点的时 ...

  9. FPGA学习过程(一)

    前言 终于有时间折腾这块fpga开发板了,不知不觉又熬夜了. 正文 实现一个呼吸灯的项目 打开quartus ii 建立工程 步骤就不讲了 新建一个pwm.v文件内容 module PWM ( inp ...

  10. vue引入zTree入门

    参考1:https://blog.csdn.net/tg928600774/article/details/80911589 参考2:https://blog.csdn.net/ylhsuper/ar ...