第一种:只有一个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(); }
第二种:有两个以上的文件,并且写出每个文件的名称
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(); }
第三种:通配符
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(); }