spring main方法中获取bean...
网上很多方法,但不适合我,因为我把applicationContext.xml分解成了4部分:application.xmldao.xmlbiz.xmlaction.xm...
网上很多方法,但不适合我,因为我把applicationContext.xml分解成了4部分:
application.xml
dao.xml
biz.xml
action.xml
我这么写不对。
BeanFactory ac = new ClassPathXmlApplicationContext("classpath:WebRoot/WEB-INF/spring/");
求解。。。 展开
application.xml
dao.xml
biz.xml
action.xml
我这么写不对。
BeanFactory ac = new ClassPathXmlApplicationContext("classpath:WebRoot/WEB-INF/spring/");
求解。。。 展开
2个回答
展开全部
不对,三种方式
方式一
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");
方式一
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");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询