首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

spring main步骤中获取bean

2012-10-28 
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");

热点排行