xxx.xml:为spring配置文件,一般命名为applicationContext.xml。
1.ApplicationContext 方式
ApplicationContext ac=new ClassPathXmlApplicationContext(new String[] {"xxx.xml"}); IAccountService as=(IAccountService)ac.getBean("accountService");
2.BeanFactory 方式
Resource rs=new ClassPathResource(new String[] {"xxx.xml"}); BeanFactory bf=new XmlBeanFactory(resource); IAccountService as=(IAccountService )bf.getBean("accountService");