转:http://blog.youkuaiyun.com/kang89/article/details/9229649
第一种:
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
ServletContext servletContext = webApplicationContext.getServletContext();
第二种:
spring 中获取applicationContext其实也很简单只要java类实现ApplicationContextAware 接口即可,这样你就可获取上下文中所有bean,很好使的。