欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

应用程序取得Spring的容器WebApplicationContext实例的通用方法,,在Spring的org.

来源: javaer 分享于  点击 6015 次 点评:246

应用程序取得Spring的容器WebApplicationContext实例的通用方法,,在Spring的org.


在Spring的org.springframework.web.context.ContextLoader类里有一个getCurrentWebApplicationContext()静态方法,应用程序可以调用这个方法获得Spring的容器。

[Java]代码

/**     * Obtain the Spring root web application context for the current thread     * (i.e. for the current thread's context ClassLoader, which needs to be     * the web application's ClassLoader).     * @return the current root web application context, or <code>null</code>     * if none found     * @see org.springframework.web.context.support.SpringBeanAutowiringSupport     */    public static WebApplicationContext getCurrentWebApplicationContext() {        return (WebApplicationContext) currentContextPerThread.get(Thread.currentThread().getContextClassLoader());    }
相关栏目:

用户点评