应用程序取得Spring的容器实例的方法,取得spring容器实例,在Spring的org.
分享于 点击 28953 次 点评:260
应用程序取得Spring的容器实例的方法,取得spring容器实例,在Spring的org.
在Spring的org.springframework.web.context.ContextLoader类里有一个getCurrentWebApplicationContext()静态方法,应用程序可以调用这个方法获得Spring的容器。
/** * 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()); }//该片段来自于http://byrx.net
用户点评