环境:基于SSH框架,外加3层结构(dao层、service层、action层) spring
IndexAction action = new IndexAction(); app
BeanFactory beanFactory = new ClassPathXmlApplicationContext( "file:E:\\eclipseWorkspace\\project\WebRoot\\WEB-INF\\applicationContext.xml" ); 框架
//由于默认的applicationContext.xml的位置我没法肯定(貌似它是找的WebContent下的WEB-INF/classes的路径,可是个人applicationContext.xml放在WEB-INF下面,我用“../applicationContext.xml”却不行,牛人请指教),因此使用的是本地绝对路径,在加载绝对路径的时候,必须在前面加上(file:) eclipse
action. commonservice = (CommonService) beanFactory .getBean( "commonServices" ); 测试
4.最后断言结果是否与预测一致 spa