Spring中获取ApplicationContextt.xml配置文件的接口
Spring中获取ApplicationContextt.xml配置文件的接口
参考:http://www.blogjava.net/xcp/archive/2011/06/22/352821.html
// Resource resource = new ClassPathResource("appcontext.xml");
// BeanFactory factory = new XmlBeanFactory(resource);
// 用classpath路径
// ApplicationContext factory = new ClassPathXmlApplicationContext("classpath:appcontext.xml");
// ApplicationContext factory = new ClassPathXmlApplicationContext("appcontext.xml");
// ClassPathXmlApplicationContext使用了file前缀是可以使用绝对路径的
// ApplicationContext factory = new ClassPathXmlApplicationContext("file:F:/workspace/example/src/appcontext.xml");
// 用文件系统的路径,默认指项目的根路径
// ApplicationContext factory = new FileSystemXmlApplicationContext("src/appcontext.xml");
// ApplicationContext factory = new FileSystemXmlApplicationContext("webRoot/WEB-INF/appcontext.xml");
// 使用了classpath:前缀,这样,FileSystemXmlApplicationContext也能够读取classpath下的相对路径
// ApplicationContext factory = new FileSystemXmlApplicationContext("classpath:appcontext.xml");
// ApplicationContext factory = new FileSystemXmlApplicationContext("file:F:/workspace/example/src/appcontext.xml");
// 不加file前缀
ApplicationContext factory = new FileSystemXmlApplicationContext("F:/workspace/example/src/appcontext.xml");
IHelloWorld hw = (IHelloWorld)factory.getBean("helloworldbean");
log.info(hw.getContent("luoshifei"));
上一篇: centos 安装php7