spring MVC如何取得dispatcher的ApplicationContext

  1、ServletContext sc=request.getSession().getServletContext();
  WebApplicationContext context=(WebApplicationContext)request.getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE);

2、  ServletContext sc=request.getSession().getServletContext();
  WebApplicationContext context=WebApplicationContextUtils.getWebApplicationContext(sc);

第二种方式取得的ApplicationContext是Spring容器的上下文

猜你喜欢

转载自qryt520.iteye.com/blog/2211969