配置文件load的几种方法

1. InputStreamResource(InputStream inputStream) 加载 Bean.xml

is = new FileInputStream("D:\\workspace\\mycripts\\src\\net\\villion\\test\\spring\\beans.xml");  

            Resource isr = new InputStreamResource(is)

xbf=new XmlBeanFactory(isr);  

 

2。利用 ClassPathResource(String path) 加载 Bean.xml

ClassPathResource res = new ClassPathResource("build.xml");  

XmlBeanFactory factory = new XmlBeanFactory(res);  

 

3

ApplicationContext  ctx = new ClassPathXmlApplicationContext("build.xml");  OR

 ApplicationContext context = new ClassPathXmlApplicationContext( 

        new String[] {"services.xml", "daos.xml"}); 

当前的*.xml文件路径是相对于WEB-INF/class路径 

 

4 .利用 FileSystemResource(String path) 加载 Bean.xml

如果配置文件在WEB-ROOT目录下的话可以用 

applicationContext = new FileSystemXmlApplicationContext("applicationContext.xml");

ApplicationContext context = new FileSystemXmlApplicationContext( 

new String[] { "WebRoot/frameworkconfig/springframeworkconfig.xml" }); 

 

 

5.XmlBeanFactory ctx = new XmlBeanFactory(new ClassPathResource("build.xml"));  

 

 

 

你可能感兴趣的:(xml,加载配置文件)