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. URI 未注册(设置 | 语言和框架 | 架构和 DTD)

    创建xml文件导入资源出错 解决方法:点击左边的小红灯,选择获取外部资源,加载资源即可

  2. 普通类中获取spring容器中的javabean对象

    spring提供了一系列的*Aware 接口,用于获取相应的对象,进行一系列的对象设置操作,此处实现ApplicationContextAware来获取ApplicationContext. 其他Aw ...

  3. Android系统编程入门系列之服务Service齐头并进多线程任务

    在上篇文章中初步了解了Android系统的四大组件之一的服务Service,在服务内可以执行无用户交互的耗时操作任务,但是包括之前关于界面系列文章在内,生命周期方法都是在主线程内被系统回调的.如果直接 ...

  4. 一个工业级、跨平台、轻量级的 tcp 网络服务框架:gevent

    前言 作为公司的公共产品,经常有这样的需求:就是新建一个本地服务,产品线作为客户端通过 tcp 接入本地服务,来获取想要的业务能力.与印象中动辄处理成千上万连接的 tcp 网络服务不同,这个本地服务是 ...

  5. Dired Mode in Emacs

    Start up Dired mode: C-x d; (List dirs: C-x C-d) Hide Dired mode window: q; Mark Mark (for group man ...

  6. 计算机网络 中国大学MOOC 哈尔滨工业大学 习题答案

    转自 https://blog.csdn.net/qq_37514135/article/details/82733651 计算机网络作业题 第一章 第一题 如图所示网络.A在t=0时刻开始向C发送一 ...

  7. Java中的形式参数和实际参数

    一.概念 1.形式参数: 就是在定义函数或过程的时候命名的参数. 通俗讲就是一个记号. 2.实际参数: 就是在执行时,调用函数或过程时,传递给函数或过程的参数. 通俗讲就是实际值. 3.参数: 就是一 ...

  8. win7环境下配置JDK&&安装Weblogic12.2.1.4.0

    win7环境下安装Weblogic12.2.1.4.0 写在前面 最近因为想复现一下weblogic的CVE-2020-2555和CVE-2020-2883漏洞,需要weblogic环境,但是vulh ...

  9. DVWA(二): Brute Force(全等级暴力破解)

    tags: DVWA Brute Force Burp Suite Firefox windows2003 暴力破解基本利用密码字典使用穷举法对于所有的账号密码组合全排列猜解出正确的组合. LEVEL ...

  10. 「移动端」touch事件,touchEvent对象

    随着智能手机普及,有越来越多的手机网页和网页版游戏,手机触摸.移动.旋转等等,多种操作.一般电脑的人机交互靠的是鼠标,而手机用的就是触摸.区别有: PC 端一个电脑只能有一个鼠标,而移动端有多点触摸. ...