Results 1 to 2 of 2

Thread: How to access resources in the application root

  1. #1
    Join Date
    Feb 2006
    Posts
    6

    Default How to access resources in the application root

    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

  2. #2
    Join Date
    Feb 2006
    Posts
    6

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •