读书人

spring main步骤中获取bean.

发布时间: 2012-09-02 21:00:34 作者: rapoo

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");

读书人网 >网络基础

热点推荐