首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

Spring的有关问题

2012-01-02 
Spring的问题!beanOfType(ListableBeanFactory lbf, Class type)谁能详细解释下这个方法!谢谢![解决办法]

Spring的问题!
beanOfType(ListableBeanFactory lbf, Class type) 

谁能详细解释下这个方法!谢谢!

[解决办法]

查找在AC=ApplicationContext里面配置的所有SpringExample.HelloBean类型的bean。注意AC是Root ApplicationContext:
Object test = org.springframework.beans.factory.BeanFactoryUtils
.beanOfType(AC, SpringExample.HelloBean.class);


这也是spring从配置文件当中确定各个特殊bean的方式:
Spring怎么知道某个bean的配置就是urlMapping?另一个bean的配置就是viewResolver?
其实很简单,把所有的bean全部读到内存里,然后通过bean的名字或类型去找就行了。通过名字去找就是简单的getBean方法,通过类型去找则使用了BeanFactoryUtils.beansOfTypeIncludingAncestors的静态方法。
上面把beanOfType改成beansOfTypeIncludingAncestors也一样。

热点排行