spring main步骤中获取bean

spring main方法中获取bean三种方式 方式一 ApplicationContext context new ClassPathXmlApplicationCo

spring main方法中获取bean
三种方式
方式一
ApplicationContext context = new ClassPathXmlApplicationContext(
        new String[] {"services.xml", "daos.xml"});
// an ApplicationContext is also a BeanFactory (via inheritance)
BeanFactory factory = (BeanFactory) context;
方式二
ApplicationContext c1 = new FileSystemXmlApplicationContext(new String[] {"beans.xml"});
方式三
XmlBeanFactory context=new XmlBeanFactory(new ClassPathResource("beans.xml"));
HelloWorld hw = (HelloWorld)context.getBean("helloworld");