Spring 中获取servletContext及WebApplicationContext以及applicationContext三者之间的关系

spring中获取servletcontext 代码如下,关键是要知道 contextLoader的强大!其它很简单

WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();

ServletContext servletContext = webApplicationContext.getServletContext();

spring 中获取applicationContext其实也很简单只要类实现ApplicationContextAware 接口即可,这样你就可获取上下文中所有bean,很好使的。

你可能感兴趣的:(Spring 中获取servletContext及WebApplicationContext以及applicationContext三者之间的关系)