Feb 8th, 2006, 06:04 AM
How to access resources in the application root
I have little problem. I need to access resources (any_files.xml), located in .../tomcat/webapps/MyApplication/*. Now I am using classloader to load resources placed in MyApplication/WEB-INF/classes/config/. I need some object which works with ServletContext, but I can't still find anything suitable for me. I need to write (anywhere in code) something like: ContextUtils.getServletContext()
Can anyone help me?
Thank you, James
Feb 8th, 2006, 10:25 AM
I have discovered solution. It is different when you are starting application context in web container or starting in Junit TestCase(AbstractDependencyInjectionSpringContextT ests). When starting in the web container it is simple:
servletContext = ((WebApplicationContext) applicationContext).getServletContext();
url = servletContext.getResource(sourceFile);
When testing application context is instance of ClassPathXmlApplicationContext class
and resources are loaded from classpath.