如何获取默认的WebApplicationContext? [英] How to get the default WebApplicationContext?

查看:333
本文介绍了如何获取默认的WebApplicationContext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要 ApplicationContext.xml 的上下文,我在 web.xml 中提供

I need the context to ApplicationContext.xml ,which I provided in web.xml as

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
 </listener> 

但我需要在控制器中控制上课。

我尝试了很多东西,包括

I tried many things including

WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();

但它没有帮助。

推荐答案

最简单的解决方案是使用 getWebApplicationContext() WebApplicationContextUtils

Easiest solution is to use getWebApplicationContext() of WebApplicationContextUtils:


找到此Web应用程序的根WebApplicationContext
,通常是
通过
ContextLoaderListener。

Find the root WebApplicationContext for this web application, which is typically loaded via ContextLoaderListener.

另见 getRequiredWebApplicationContext()

这篇关于如何获取默认的WebApplicationContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆