SSM框架中如何获取ApplicationContext

我搭建了一个SSM框架的Web项目,Spring的配置文件我在web.xml中加载了,我想在程序中获得ApplicationContext对象,如何获取,尽可能不要通过指定配置文件路径的方式去获取。
附上配置文件:
applicationContext-Dao.xml:

https://img4.mukewang.com/5cc0110200012ce308000365.jpg

applicationContext-Service.xml:

https://img.mukewang.com/5cc011040001fc8408000249.jpg

applicationContext-Transaction.xml:

https://img2.mukewang.com/5cc011060001ba9c08000267.jpg

web.xml:

https://img.mukewang.com/5cc0110800016c6f08000493.jpg

获取applicationContext的代码:

https://img3.mukewang.com/5cc0110a00012ee908000323.jpg

第14行需要获取到applicationContext,请问怎么获取


大话西游666
浏览 1308回答 3
3回答

慕的地6264312

实现ApplicationContextAware接口

米琪卡哇伊

WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();XXXService xxxService=(XXXService ) wac.getBean("xxxService");
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java