Maybe the title is a little bit obscure, but let me explain… In a servlet, to know the webapp root, you’ll do:
String path = getServletContext.getRealPath("/");
the problem is that you have to be in a servlet. Now I’d like to pass this path to a generic bean, that is wired up in my servlet-context.xml . How to do that?
Your bean can request to be injected with the current
ServletContext, either by implementing theServletContextAwareinterface, or else using autowiring, i.e.Use whichever one fits your code & config best.
You might also to consider using Spring’s
ServletContextResourceclass to perform filesystem access against theServletContext, e.g. usingServletContextResource.getFile().