1: spring中获取ApplicationContext
public class ApplicationContextUtil implements ApplicationContextAware 即可
2: spring mvc中获取Request
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
3: spring mvc中获取WebApplicationContext
3.1 : WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
3.2 :
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext());