spring配置文件有以下3种配置方式:
一、简单单个spring配置文件:applicationContext.xml
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
RegisterDAO registerDAO = (RegisterDAO)ac.getBean("registerDAO");
(registerDAO为在applicationContext.xml中注入的bean)
二、多个spring配置文件,文件名称数组:
ApplicationContext ac = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml","dao.xml"});
RegisterDAO registerDAO = (RegisterDAO)ac.getBean("registerDAO");
(registerDAO为在dao.xml中注入的bean)
三、多个spring配置文件,也可以使用通配符:
ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:/*.xml");
说明:以上spring配置文件都是放在src目录下的,如果src下还有package,需要带上package路径,例如:spring配置文件放在src下的springxml包下,则使用通配符的配置方式为:
ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:springxml/*.xml");