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  事件传递

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  事件传递

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. FastAPI实战:简易MockServe

    Mock 我个人理解就是为了伪造返回结果的东西,MockServe通常说的就是接口未开放完成但是现在需要调用,所以无论是通过转发还是直接访问这个url,其结果基本就是自己定义的 当然做仔细点就是 给个 ...

  2. Docker限制

    前言 Docker系列文章: 此篇是Docker系列的第十篇,大家一定要按照我做的Demo都手敲一遍,印象会更加深刻的,马上就开始Kubernetes,加油!一起前行! 为什么要学习Docker Do ...

  3. 终拿字节Offer...动态规划复盘...

    大家好!我是 Johngo 呀! 和大家一起刷题不快不慢,没想到已经进行到了第二阶段,「动态规划」这部分题目很难,而且很不容易理解,目前我的题目做了一半,凭着之前对于「动态规划」的理解和最近做的题目做 ...

  4. SpringCloud升级之路2020.0.x版-7.从Bean到SpringCloud

    本系列为之前系列的整理重启版,随着项目的发展以及项目中的使用,之前系列里面很多东西发生了变化,并且还有一些东西之前系列并没有提到,所以重启这个系列重新整理下,欢迎各位留言交流,谢谢!~ 在理解 Spr ...

  5. ElasticSearch入门检索

    前面简介说到 elsatic是通过RestFul API接口操作数据的,可以通过postman模拟接口请求测试一下 一._cat 1.GET /_cat/nodes:查看所有节点 2.GET /_ca ...

  6. Java架构师-十项全能学习笔记(1)

    Java架构师-十项全能学习笔记(1) @Configuration @EnableStateMachine public class OrderStateMachineConfig extends ...

  7. mysql的安装,一步一步的教你

    1.下载mysql安装包 ,我这里安装的是mysql-5.6.41-winx64 (https://downloads.mysql.com/archives/community/) 选择自己的版本 我 ...

  8. Yara规则学习

    01 定义 官网: YARA is a tool aimed at (but not limited to) helping malware researchers to identify and c ...

  9. DevOps基础的认识与工具实践

    什么是DevOps DevOps 强调的是高效组织团队之间如何通过自动化的工具协作和沟通来完成软件的生命周期管理,从而更快.更频繁地交付更稳定的软件 Devops 包含了敏捷开发,测试,运维 DevO ...

  10. 用Python爬取《王者荣耀》英雄皮肤数据并可视化分析,用图说话

    大家好,我是辰哥~ 今天辰哥带大家分析一波当前热门手游<王者荣耀>英雄皮肤,比如皮肤上线时间.皮肤类型(勇者:史诗:传说等).价格. 1.获取数据 数据来源于<王者荣耀官方网站> ...