我搭建了一个SSM框架的Web项目,Spring的配置文件我在web.xml中加载了,我想在程序中获得ApplicationContext对象,如何获取,尽可能不要通过指定配置文件路径的方式去获取。附上配置文件:applicationContext-Dao.xml:applicationContext-Service.xml:applicationContext-Transaction.xml:web.xml:获取applicationContext的代码:第14行需要获取到applicationContext,请问怎么获取
3 回答

米琪卡哇伊
TA贡献1998条经验 获得超6个赞
WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
XXXService xxxService=(XXXService ) wac.getBean("xxxService");
添加回答
举报
0/150
提交
取消