標籤:fill rap void lap context count() dex hid otto
第一種:只有一個xml檔案
public static void main(String[] args) { ApplicationContext ac = null; try { ac = new ClassPathXmlApplicationContext("beans.xml"); //ac = new ClassPathXmlApplicationContext("classpath:beans.xml"); } catch (Exception e) { LOGGER.error("spring啟動錯誤", e); } Account test3 = (autoAccount) ac.getBean("account"); test3.account();}
13 1
public static void main(String[] args) {
2
ApplicationContext ac = null;
3
try {
4
ac = new ClassPathXmlApplicationContext("beans.xml");
5
//ac = new ClassPathXmlApplicationContext("classpath:beans.xml");
6
} catch (Exception e) {
7
LOGGER.error("spring啟動錯誤", e);
8
}
9
10
11
Account test3 = (autoAccount) ac.getBean("account");
12
test3.account();
13
}
第二種:有兩個以上的檔案,並且寫出每個檔案的名稱
public static void main(String[] args) { ApplicationContext ac = null; try { ac = new ClassPathXmlApplicationContext(new String[] {"classpath:beans.xml", "classpath:quartz.xml"}); } catch (Exception e) { LOGGER.error("spring啟動錯誤", e); } Account test3 = (autoAccount) ac.getBean("account"); test3.account(); }
13 1
public static void main(String[] args) {
2
ApplicationContext ac = null;
3
try {
4
ac = new ClassPathXmlApplicationContext(new String[] {"classpath:beans.xml", "classpath:quartz.xml"});
5
} catch (Exception e) {
6
LOGGER.error("spring啟動錯誤", e);
7
}
8
9
10
Account test3 = (autoAccount) ac.getBean("account");
11
test3.account();
12
13
}
第三種:萬用字元
public static void main(String[] args) { ApplicationContext ac = null; try { ac = new ClassPathXmlApplicationContext("classpath:/*.xml"); } catch (Exception e) { LOGGER.error("spring啟動錯誤", e); } Account test3 = (autoAccount) ac.getBean("account"); test3.account();}
12 1
public static void main(String[] args) {
2
ApplicationContext ac = null;
3
try {
4
ac = new ClassPathXmlApplicationContext("classpath:/*.xml");
5
} catch (Exception e) {
6
LOGGER.error("spring啟動錯誤", e);
7
}
8
9
10
Account test3 = (autoAccount) ac.getBean("account");
11
test3.account();
12
}
ApplicationContext進行測試的簡單使用