spring 容器初始化

spring容器初始化,一般用于JUnit中手工初始化
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");

猜你喜欢

转载自sha1064616837.iteye.com/blog/2203297