Spring MVC 获取WebApplicationContext、ServletContext

不用依赖ServletContext

// 取得WebApplicationContext
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();

// 取出Bean
webApplicationContext.getBean("xxx",xxx.class) ;

// 取出ServletContext
ServletContext servletContext = webApplicationContext.getServletContext();

你可能感兴趣的:(Spring MVC 获取WebApplicationContext、ServletContext)