首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Spring惯用的加载配置文件方法

2012-10-21 
Spring常用的加载配置文件方法常用加载配置文件的几种方法,需要注意的地方! 小结  这篇文章主要谈论了如何

Spring常用的加载配置文件方法
常用加载配置文件的几种方法,需要注意的地方!


小结

  这篇文章主要谈论了如何加载Spring的配置文件,一般来说,就是BeanFactory和ApplicationContext.最常使用的、简单的BeanFactory实现是org.springframework.beans.factory.xml.XmlBeanFactory,其加载方式为:BeanFactory factory = new XmlBeanFactory(Resource resource)

  这里resource必须是xml格式。Resource包括: AbstractResource, ClassPathResource, FileSystemResource, InputStreamResource, ServletContextResource, UrlResource.这篇文章 谈了常用的三种:ClassPathResource, FileSystemResource, InputStreamResource.

  ApplicationContext包括了BeanFactory的所有功能,也要比BeanFactory强大的多(以后会详细介绍的)。这里只简单的使用了ClassPathXmlApplicationContext加载了Bean配置文件。你可以将log4j.properties中的“Warn”改为“Debug”, 对比一下和ClassPathResource的输出,

  在Eclipse中,bean2.xml、bean4xml虽然都是放在源文件夹(src)目录下,但实际上,是由已经编译好的Test.class从类文件夹(这里是bin文件夹)中加载的。

热点排行