获取SpringMvc对应的子容器

来源:互联网 发布:美国宝宝的好处知乎 编辑:程序博客网 时间:2024/05/18 04:04
  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名字
阅读全文
0 0
原创粉丝点击