Announcement Announcement Module
No announcement yet.
ServletContext, ApplicationContext, WebApplicationContext? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • ServletContext, ApplicationContext, WebApplicationContext?

    I am trying to figure something out that I believe should be straightforward, but with which I am having difficulty.

    I have a Spring managed, CXF web service, deployed to Tomcat 6.0.26. I need to know which of ServletContext, ApplicationContext, or WebApplicationContext I use to get where the web service is running. E.g. if the web service is deployed into Tomcat with the following directory structure "C:\Program Files\apache-tomcat-6.0.26\webapps\MyWebService\" from a .war, MyWebService.war, located in the same location, which of these contexts do I use to get the web service's path, the "C:\Program Files\apache-tomcat-6.0.26\webapps\MyWebService". Basically, I need to get the location of <TOMCAT_HOME>/webapps since no CATALINA_HOME environment variable may be set.

    At <TOMCAT_HOME>/webapps, at an adjacent location to my running web service, there is a XML file I need to parse, read, and write to from my web service. Previously, I used a JNDI setting in context.xml for this file's location but since my application now needs to support multiple platforms, Windows 2003 Server, Windows 2008 Server, Mac OS 10.5 server, and Mac OS 10.6 server, I don't want to maintain 4 different versions of the context.xml file. So I want to place this XML file at a location in Tomcat that my web service knows about. It will be at "C:\Program Files\apache-tomcat-6.0.26\MyConfigFile\MyConfigFile.xml".

    I hope I have made my situation clear. Please let me know if this needs additional information.

    Mike Sucena
    Software Engineer

  • #2
    Please help!!!!

    I have tried the following:

    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(ctx);
    String appCtxPath = wac.getServletContext().getRealPath("");
    But this generates:
    java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
    Even though I do have following in my web.xml
    FYI-I am using Spring 3.0
    Last edited by msucena; Oct 20th, 2010, 04:18 PM.