1. 在我们使用springMVC作为action时,spring启动时默认会创建两个容器,spring是父容器,springMVC是子容器,子容器可以访问父容器对象和属性,但是父容器不能访问子容器的
2.在请求到达action时处理请求的是子容器内的对象,父容器内的controller对象虽然存在,但是经试验用不上
3.分别获取父子容器
父容器
ApplicationContext applicationContext =
WebApplicationContextUtils.getWebApplicationContext(ServletContext);
子容器
WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(httpServletRequest.getServletContext(),"org.springframework.web.servlet.FrameworkServlet.CONTEXT.你在web.xml中配置的dispatcherServlet的<servlet-name>");
2的证明可以参考我的这篇博客
https://blog.csdn.net/baidu_38609744/article/details/86075578