spring中获取servletcontext 代码如下,关键是要知道 contextLoader的强大!其它很简单
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
ServletContext servletContext = webApplicationContext.getServletContext();
spring 中获取applicationContext其实也很简单只要类实现ApplicationContextAware 接口即可,这样你就可获取上下文中所有bean,很好使的。