第一种:只有一个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
}