xmlbeanfactorybean方法用什么代替了

二次元同好交流新大陆
扫码下载App
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(6850)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_084064',
blogTitle:'spring BeanFactory 实现类的getBean方法',
blogAbstract:'这个方法是返回一个对象实例根据一个id或者name,这个id 或者 name 将会在配置文件里出现如:\r\n&bean id=\"abc\" class=\"com.yourcompany.Abc\"&&/bean&\r\n系统会根据给出的class属性构造一个实例出来,然后强制转换:\r\nBeanFactory factory=new XmlBeanFactory(new ClassPathResource(\"applicationContext.xml\"));Abc abc=(Abc)factory.getBean(\"abc\");但有看过这样的代码:&bean id=\"bean\" class=\"org.springframework.aop.framework.ProxyFactoryBean\"& ',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:7,
publishTime:3,
permalink:'blog/static/',
commentCount:1,
mainCommentCount:1,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&1572人阅读
Spring(22)
DefaultListableBeanFactory可以说是spring IOC的始祖了。我们曾经常用的是它的子类XMLBeanFactory,如以下代码:
XMLBeanFactoryfactory = new XMLBeanFactory(new ClassPathResource(&beans.xml&))
这行代码虽然简单,但其中包含了很多&#20540;得思考的地方,也就是spring的资源载人的过程。
为什么参数是一个ClassPathResource对象而不是直接使用beans.xml文件的路径呢?
因为:spring将资源文件都抽象成了不同的resource,通过不同的resource,如classpathresource、filesystemresource等,使得工厂面对是不同的resource对象,当这行代码执行完毕,工厂就在内存中构建完了,对象的装配过程也完成了。
过程如下:
1、读文件:beans.xml
2、解析文件,形成一个一个的元素
3、将bean装载成对象放到factory中
4、从factory中读取对象
好了,那么既然常用的是XMLBeanFactoryfactory ,我们为什么又要去讲DefaultListableBeanFactory呢?
我们看一下源码:
* @author Rod Johnson
* @author Juergen Hoeller
* @author Chris Beams
* @since 15 April 2001
* @see org.springframework.beans.factory.support.DefaultListableBeanFactory
* @see XmlBeanDefinitionReader
* @deprecated as of Spring 3.1 in favor of {@link DefaultListableBeanFactory} and
* {@link XmlBeanDefinitionReader}
@Deprecated
@SuppressWarnings({&serial&, &all&})
public class XmlBeanFactory extends DefaultListableBeanFactory {
@Deprecated,说明它被废弃了。为什么废弃呢?可以看到代码中只有两个构造方法,而且建议使用DefaultListableBeanFactory和XmlBeanDefinitionReader
那么,接下来我们看一下使用DefaultListableBeanFactory和XmlBeanDefinitionReader如何实现加载的过程:
ClassPathResource resource = new ClassPathResource(&beans.xml&);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader
reader = new XmlBeanDefinitionReader(factory);
reader.loadBeanDefinitions(resource);这个过程与XmlBeanFactory是一样的,不过XmlBeanFactory把XmlBeanDefinitionReader私有化了。
通过这个代码,我们可以总结出Spring加载资源并装配对象的过程如下:
1. 定义好Spring的配置文件。
2. 通过Resource对象将Spring配置文件进行抽象,抽象成一个Resource对象。
3. 定义好Bean工厂(各种BeanFactory)。
4. 定义好XmlBeanDefinitionReader对象,并将工厂作为参数传递进去供后续回调使用。
5. 通过XmlBeanDefinitionReader对象读取之前抽象出的Resource对象(包含了XML文件的解析过程)。
6. IoC容器创建完毕,用户可以通过容器获取到所需的对象信息。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:533704次
积分:9646
积分:9646
排名:第1152名
原创:282篇
转载:31篇
评论:1625条
文章:14篇
阅读:14190
(2)(1)(4)(3)(5)(1)(1)(2)(2)(2)(2)(2)(2)(2)(2)(2)(2)(1)(4)(4)(4)(4)(4)(4)(4)(4)(4)(4)(4)(1)(4)(4)(2)(4)(4)(4)(5)(4)(4)(4)(4)(4)(4)(4)(8)(14)(7)(10)(9)(4)(8)(8)(3)(6)(8)(8)(4)(15)(1)(8)(11)(7)(1)(3)(4)(5)(1)(1)(2)(11)(6)(2)<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&BeanFactory接口包含的方法
spring容器的接口是BeanFactory 他有一个子接口ApplictionContext也称为上下文
BeanFactory接口包含的方法如下:
1.boolean containsBean(String
name):判断Spring容器是否包含id为name的Bean实例
getBeam(Class&T&
requiredType):获取Spring容器中属于requiredType类型的、唯一的Bean实例。
3.Object getBean(String name):返回容器id为name的Bean实例
4.&T& T getBean(String name,class
requiredType):返回容器中id为name,并且类型为requiredType的Bean
5.Class&?&getType(String
name):返回容器中指定Bean实例的类型
BeanFactory有一个常用的实现类org.springframework.beans.factory.xml.XMLBeanFactory类
ApplicationContext是BeanFactory的子接口
常用的实现类FileSystemXmlApplicationContext、ClassPathXmlApplicationContext和
AnnotationconfigApplicationContext
web应用中使用Spring容器通常有XmlWebApplicationContext、AnnotationConfigWebApplicationContext
创建Spring容器时需通过resource接口传入xml配置文件
实例化BeanFactory的2中方法
//搜索当前路径下的beans.xml文件创建Resource对象
InputStreamResource isr = new
FileSystemResource("bean.xml");
//以Resource对象作为参数,创建BeanFactory实例
XmlBeanFactory factory = new XmlBeanFactory(isr);
ClassPathResource res = new ClassPathResource("beans.xml");
XmlBeanFactory factory = new XmlBeanFactory(res);
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

我要回帖

更多关于 spring beanfactory 的文章

 

随机推荐