Simply implement
ServletContextAware
and ServletConfigAware
interfaces and override below methods.@Controller @RequestMapping (value = "/magic" ) public class SimpleController implements ServletContextAware, ServletConfigAware { private ServletContext context; private ServletConfig config; @Override public void setServletConfig( final ServletConfig servletConfig) { this .config = servletConfig; } @Override public void setServletContext( final ServletContext servletContext) { this .context = servletContext; } //other code } |
Thank you for this amazing answer Rajesh,
ReplyDeleteI have one question, will this make SimpleController as prototype bean since every request will have its own ServletContext.
Thanks
Maneesh