PDA

View Full Version : How to access resources in the application root


kuubajz
Feb 8th, 2006, 07:04 AM
Hi all,

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

kuubajz
Feb 8th, 2006, 11: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.

That's all.

James