应用程序取得Spring的容器WebApplicationContext实例的通用方法,,在Spring的org.
分享于 点击 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()); }
用户点评