ApplicationContext中getBean详解
在org.springframework.context包中有一个接口叫 applicationContext
applicationContext中有一个getBean方法,此方法继承之BeanFactory
Methods inherited from interface org.springframework.beans.factory.BeanFactory
containsBean, getAliases, getBean, getBean, getBean, getType, isPrototype, isSingleton, isTypeMatch
在BeanFactory中getBean描述如下
Object |
getBean(String name) Return an instance, which may be shared or independent, of the specified bean. |
返回一个指定bean的实例,它可以是共享的、也可以是独立的。 返回的是对象
Method Detail
Object getBean(String name)throws BeansException
- Return an instance, which may be shared or independent, of the specified bean.
This method allows a Spring BeanFactory to be used as a replacement for the Singleton or Prototype design pattern. Callers may retain references to returned objects in the case of Singleton beans.
Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.
-
- Parameters:
name- the name of the bean to retrieve- Returns:
- an instance of the bean
- Throws:
NoSuchBeanDefinitionException- if there is no bean definition with the specified nameBeansException- if the bean could not be obtained- 实例:
-
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
UserService service = (UserService)ctx.getBean("userService");
因为getBean返回一个对象,所以要强制转换
ApplicationContext中getBean详解的更多相关文章
- Spring Boot源码中模块详解
Spring Boot源码中模块详解 一.源码 spring boot2.1版本源码地址:https://github.com/spring-projects/spring-boot/tree/2.1 ...
- winxp计算机管理中服务详解
winxp计算机管理中服务详解01 http://blog.sina.com.cn/s/blog_60f923b50100efy9.html http://blog.sina.com.cn/s/blo ...
- cocos2dx常见的46中+22中动作详解
cocos2dx常见的46中+22中动作详解 分类: iOS2013-10-16 00:44 1429人阅读 评论(0) 收藏 举报 bool HelloWorld::init(){ ///// ...
- Android中Context详解 ---- 你所不知道的Context
转自:http://blog.csdn.net/qinjuning/article/details/7310620Android中Context详解 ---- 你所不知道的Context 大家好, ...
- iOS中-Qutarz2D详解及使用
在iOS中Qutarz2D 详解及使用 (一)初识 介绍 Quartz 2D是二维绘图引擎. 能完成的工作有: 绘制图形 : 线条\三角形\矩形\圆\弧等 绘制文字 绘制\生成图片(图像) 读取\生成 ...
- 【转】declare-styleable的使用(自定义控件) 以及declare-styleable中format详解
原文网址:http://www.cnblogs.com/622698abc/p/3348692.html declare-styleable是给自定义控件添加自定义属性用的 1.首先,先写attrs. ...
- Python中dict详解
from:http://www.cnblogs.com/yangyongzhi/archive/2012/09/17/2688326.html Python中dict详解 python3.0以上,pr ...
- 【转】 java中HashMap详解
原文网址:http://blog.csdn.net/caihaijiang/article/details/6280251 java中HashMap详解 HashMap 和 HashSet 是 Jav ...
- java中HashMap详解(转)
java中HashMap详解 博客分类: JavaSE Java算法JDK编程生活 HashMap 和 HashSet 是 Java Collection Framework 的两个重要成 ...
随机推荐
- 58到家mysql数据库军规及解读分享
一.基础规范 (1)必须使用InnoDB存储引擎 解读:支持事务.行级锁.并发性能更好.CPU及内存缓存页优化使得资源利用率更高 (2)必须使用UTF8字符集 解读:万国码,无需转码,无乱码风险,节省 ...
- CF851 C 暴力
给出n个5维下的点,求点a不与其它任意的b,c重合,向量ab,ac的夹角都为钝角,这样的点个数,并打印它们. 转换二维下的求角度的函数为五维的,而且由于要求角度大于90度,在二维情况下最多有4个点,也 ...
- 【CodeForces】915 D. Almost Acyclic Graph 拓扑排序找环
[题目]D. Almost Acyclic Graph [题意]给定n个点的有向图(无重边),问能否删除一条边使得全图无环.n<=500,m<=10^5. [算法]拓扑排序 [题解]找到一 ...
- JavaScript使用数组
for循环遍历 //js的数组里可以存各种类型 var arr =[1,5,true,false,'小明']; //遍历 for(var i=0;i<arr.length;i++){ alert ...
- NYOJ 756 重建二叉树 (二叉树)
题目链接 描述 题目很简单,给你一棵二叉树的后序和中序序列,求出它的前序序列(So easy!). 输入 输入有多组数据(少于100组),以文件结尾结束.每组数据仅一行,包括两个字符串,中间用空格隔开 ...
- lintcode 443.岛屿的个数
在v2ex上看到有人提到了这个,感觉挺简单的,没忍住还是试一下.... 基本的染色法. AC代码: public class Solution { /** * @param grid a boolea ...
- 购物车中的input输入框只能输入数字和输入为0的时候默认为1
<input type="text" value="1" onkeyup="value=(parseInt((value=value.repla ...
- django【ORM】 通过外键字段找对应类
两个方法其实是一种,用哪个都行,看实例: 方法一: 从list_filter中的字符串,找到model对象的字段,然后得到这个外键对应的类 循环,把list_filter中对应的类所有对象 方法二 ...
- UBIFS学习笔记
在做项目的时候,发现flash芯片有异常现象,经过打印分析,发现是UBIFS方面设置有一些问题,经过查阅一部分资料,最终得到问题的答案. 在解决问题的过程中,发现打印信息比较重要,但网上并没有直接的相 ...
- 配置kernel的log buf大小(如果kmsg log被覆盖)
如果在打印kmsg log时发现log被覆盖,log 的buf不够大可以使用默认配置调buf: defconfig CONFIG_LOG_BUF_SHIFT=20 (默认是17 2的17次方) ...