简体   繁体   English

从xml文件Spring中读取bean定义

[英]reading the bean definition from xml file Spring

While reading the bean definition from an xml file, which of the below two methods is best. 从xml文件读取bean定义时,以下两种方法中最好的一种。 I remember reading about Resource , that using this is fast or something like that but don't know exactly. 我记得读过有关Resource ,它使用它的速度很快或类似的东西,但并不清楚。

Resource rs = new ClassPathResource("hello.xml");
BeanFactory  factory = new XmlBeanFactory(rs);

or 要么

BeanFactory  factory = new XmlBeanFactory(new FileInputStream("myBean.xml"));

您可能更喜欢直接使用http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/context/support/ClassPathXmlApplicationContext.html ,因为此类实现了BeanFactory接口并且具有更多优点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM