myeclipse下的main方法如何加载spring、struts等配置文件

如题所述

使用ApplicationContext接口的对应实现类加载spring配置文件
一般常用的有ClassPathXmlApplicationContext类和FileSystemXmlApplicationContext类
分别读取classpath目录和指定的文件系统目录下的spring配置文件
比如你的spring配置文件叫applicationContext.xml,放置在资源文件夹的根目录下面,就可以写成
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
就可以加载了

至于struts配置文件,如果你使用的是struts2,而且目的是做单元测试的话,有两种测试方式
struts2提供了struts2-junit-plugin-2.2.1.1.jar包进行struts单框架测试及struts整合spring后的spring测试工具,两个基类StrutsTestCase、StrutsSpringTestCase,从名字你也应该知道分别针对哪种情况了,直接继承就可以使用了,不需要自己加载配置来自:求助得到的回答
温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2016-02-15
Resource resource = new ClassPathResource("../applicationContext.xml");
BeanFactory factory = new XmlBeanFactory(resource);
interceptionNeedInfo = (IInterceptionNeedInfo)factory.getBean("interceptionNeedInfo");
ICodetypeAction codetype = (ICodetypeAction)factory.getBean("codetypeAction");

参照这个。
applicationContext.xml 位置在WEB-INF中本回答被提问者采纳
第2个回答  2013-01-23
ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml");

参考这个类
相似回答