1、通过spring配置文件获取,但是需注意路径从WebContent级别写,如下:
ApplicationContext ac = new FileSystemXmlApplicationContext("/WebRoot/WEB-INF/config/common/spring/applicationContext.xml");
2、通过ServletContext获取,如下:
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext());
本文介绍了两种在Spring框架中加载应用上下文的方法:一是通过spring配置文件直接加载;二是利用ServletContext来获取Web应用上下文。这两种方法适用于不同的场景,前者更适用于简单的测试环境,而后者则适用于Web应用。
2670

被折叠的 条评论
为什么被折叠?



