1
2
3
4
5
6
7
8
9
10 |
//获取父容器
WebApplicationContext
rootWac
=
ContextLoader
.
getCurrentWebApplicationContext
();
//获取servletContext
ServletContext
servletContext
=
rootWac
.
getServletContext
();
//获取子容器
WebApplicationContext
wac
=
WebApplicationContextUtils
.
getWebApplicationContext
(
servletContext
,
"org.springframework.web.servlet.FrameworkServlet.CONTEXT.springServlet"
);
//获取子容器里的bean
subWac
.
getBean
(
beanName
);
|
来自CODE的代码片
WebApplicationContext.java
注:
在servletContext中,
父容器的key是:
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
子容器的key是:"org.springframework.web.serrvlet.FrameworkServlet.CONTEXT."+Servlet名字,