First: Only one XML file
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();}
<textarea spellcheck="false" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none" tabindex="0" readonly=""></textarea>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 start Error", E);
8
}
9
10
11
Account test3 = (autoaccount) Ac.getbean ("account");
12
Test3.account ();
13
}
The second type: There are more than two files, and write out the name of each file
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(); }
<textarea spellcheck="false" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none" tabindex="0" readonly=""></textarea>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 start Error", E);
7
}
8
9
10
Account test3 = (autoaccount) Ac.getbean ("account");
11
Test3.account ();
12
13
}
The third type: wildcard characters
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();}
<textarea spellcheck="false" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none" tabindex="0" readonly=""></textarea>12 1
{
2
ApplicationContext ac = null;
3
try {
4
ac = new Classpathxmlapplicationcontext ("Classpath:/*.xml");
5
} catch (Exception e) {
6
logger.error ("Spring start Error", E);
7
}
8
9
10
Account test3 = (autoaccount) Ac.getbean ("account");
11
Test3.account ();
12
}
Simple use of ApplicationContext for testing