ApplicationContext進行測試的簡單使用
阿新 • • 發佈:2018-02-26
account contex pri pan -i bsp nes ger utl 第一種:只有一個xml文件
第二種:有兩個以上的文件,並且寫出每個文件的名稱
第三種:通配符
13 1public 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(); }
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) {
7LOGGER.error("spring啟動錯誤", e);8
}
9
10
11 Account test3 = (autoAccount) ac.getBean("account");
12 test3.account();
13}
第二種:有兩個以上的文件,並且寫出每個文件的名稱
13 1public 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(); }
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 1public 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進行測試的簡單使用