Spring Dependency Injection浅析
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浅析的更多相关文章
- Spring点滴七:Spring中依赖注入(Dependency Injection:DI)
Spring机制中主要有两种依赖注入:Constructor-based Dependency Injection(基于构造方法依赖注入) 和 Setter-based Dependency Inje ...
- Benefits of Using the Spring Framework Dependency Injection 依赖注入 控制反转
小结: 1. Dependency Injection is merely one concrete example of Inversion of Control. 依赖注入是仅仅是控制反转的一个具 ...
- spring in action学习笔记一:DI(Dependency Injection)依赖注入之CI(Constructor Injection)构造器注入
一:这里先说一下DI(Dependency Injection)依赖注入有种表现形式:一种是CI(Constructor Injection)构造方法注入,另一种是SI(Set Injection) ...
- [转载][翻译] IoC 容器和 Dependency Injection 模式
原文地址:Inversion of Control Containers and the Dependency Injection pattern 中文翻译版本是网上的PDF文档,发布在这里仅为方便查 ...
- 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 ...
- 【译】Dependency Injection with Autofac
先说下为什么翻译这篇文章,既定的方向是架构,然后为了学习架构就去学习一些架构模式.设计思想. 突然有一天发现依赖注入这种技能.为了使得架构可测试.易维护.可扩展,需要架构设计为松耦合类型,简单的说也就 ...
- 黄聪:Microsoft Enterprise Library 5.0 系列教程(八) Unity Dependency Injection and Interception
原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(八) Unity Dependency Injection and Interception 依赖注入容器Uni ...
- Srping - bean的依赖注入(Dependency injection)
目录 1 概述 2 两种基本的依赖注入方式 2.1 构造函数方式 2.2Setter方式 3 其他依赖注入功能 3.1 <ref/>标签引用不同范围的bean 3.2 内部bean 3.3 ...
- Inversion of Control Containers and the Dependency Injection pattern
https://martinfowler.com/articles/injection.html One of the entertaining things about the enterprise ...
随机推荐
- Cookie、Session、JWT在koa中的应用及实现原理
目录 Cookie 重要属性 实现原理 cookie签名实现原理 注意事项 Session 实现原理 JWT 使用方式 组成 实际应用 实现原理 前端存储方式 cookie session local ...
- js--class类、super和estends关键词的学习笔记
前言 JavaScript 语言在ES6中引入了 class 这一个关键字,在学习面试的中,经常会遇到面试官问到谈一下你对 ES6 中class的认识,同时我们的代码中如何去使用这个关键字,使用这个关 ...
- Mybatis学习笔记-日志
日志工厂 如果一个数据库操作出现异常,在排错时,则需要日志 SLF4J Apache Commons Logging(COMMONS_LOGGING) LOG4J LOG4J2 JDK logging ...
- 年薪60W的Android程序员究竟多累、多苦?一条高赞评论扎了无数人的心
为啥经常听到程序员朋友说自己太辛苦了.太累了,其实原因很简单:干活苦.竞争大.技术致富难. 干活苦: 有新闻说晚上十点某领导在微信群要求下属在十分钟内回复,一员工因休息早而没及时回复被裁了. 对于程序 ...
- Java 执行控制流程
1.带标签的break会中断并跳出标签所指的循环: 2.带标签的continue会中断本次循环,并开始标签所指处循环的下一轮循环.
- Groovy正则表达式复杂逻辑判断实例
下面的两个pattern(p1和p2)分别代表了(A or B) and (C or D)和(A and B) or (C and D)的跨行匹配结果,当然还可以用正则表达式构建更复杂的pattern ...
- 手把手和你一起实现一个Web框架实战——EzWeb框架(二)[Go语言笔记]Go项目实战
手把手和你一起实现一个Web框架实战--EzWeb框架(二)[Go语言笔记]Go项目实战 代码仓库: github gitee 中文注释,非常详尽,可以配合食用 上一篇文章我们实现了框架的雏形,基本地 ...
- scrapy爬虫框架使用
一.scrapy框架 1.什么是scrapy: 爬虫中封装好的一个明星框架.功能:高性能的持久化存储,异步的数据下载,高性能的数据解析,分布式. 2.使用方法: 安装: 下载tiwisted,此处位下 ...
- sqli-labs lesson 26-27a
less 26: 因为本关在windows上运行可能会出现字符转义(apacche下空格无法转义)错误,所以在docker上搭建好sqli-labs 在win2003上远程登录sqli-labs 先执 ...
- Sqli-Labs less32-37
Less-32 前置基础知识:宽字节注入 参考链接: https://blog.csdn.net/helloc0de/article/details/76180190 https://blog.csd ...