获取SpringMvc对应的子容器时间:2022-12-10 23:58:33 1 2 3 4 5 6 7 8 9 10 //获取父容器WebApplicationContext rootWac=ContextLoader.getCurrentWebApplicationContext();//获取servletContextServletContext servletContext = rootWac.getServletContext(); //获取子容器WebApplicationContext wac=WebApplicationContextUtils.getWebApplicationContext(servletContext,"org.springframework.web.servlet.FrameworkServlet.CONTEXT.springServlet" );//获取子容器里的beansubWac.getBean(beanName); 来自CODE的代码片WebApplicationContext.java 注:在servletContext中,父容器的key是:WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,子容器的key是:"org.springframework.web.serrvlet.FrameworkServlet.CONTEXT."+Servlet名字,