或者
org.springframework.core.io.Resource fileRource = new ClassPathResource("test.xml");
獲取文件:fileRource.getFile();
獲取文件流:fileRource.getInputStream();
獲取到xml:進(jìn)行解析:例:
Document document = new SAXReader().read(fileRource.getFile());
//獲取到myxml下面的template節(jié)點(diǎn)為id為test的節(jié)點(diǎn)
Element element = (Element) document.selectSingleNode("/myXml/template[@id='test']");
//解析xml,并獲取到節(jié)點(diǎn)里的值。
String id = element.attributeValue("id");
//獲取到j(luò)ava的臨時(shí)文件:
System.getProperty("java.io.tmpdir"),
//windows是,unix是/
File.separator
一、簡單的用ApplicationContext做測試的話,獲得Spring中定義的Bean實(shí)例(對(duì)象).可以用:
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
RegisterDAO registerDAO = (RegisterDAO)ac.getBean("RegisterDAO",RegisterDao.class);
在主文件中引入副文件:
在主文件中可以引入一些properties文件,作為applicationContext中的變量