想获取spring 文件,相对路径该怎么写
在TOMCAT里面路径为
D:\Tomcat 6.0\webapps\work\WEB-INF\applicationContext.xml
其中work为工程名
在Myeclipse中的路径为
work/WebRoot/WEB-INF\applicationContext.xml
请问我该怎么写相对路径
ApplicationContext context=new FileSystemXmlApplicationContext("?");
该语句在WORK/src/com.service.impl 中的文件被调用。该怎么写才可以在通用

解决方案 »

  1.   

    ApplicationContext context=new FileSystemXmlApplicationContext("/WebRoot/WEB-INF/applicationContext.xml");
    我这样写,解析后变为
     IOException parsing XML document from file [D:\Tomcat 6.0\bin\WebRoot\WEB-INF\applicationContext.xml]; nested exception is java.io.FileNotFoundException: WebRoot\WEB-INF\applicationContext.xml (系统找不到指定的路径。)
    里面报错
      

  2.   

    ApplicationContext  act=new FileSystemXmlApplicationContext("/WebRoot/WEB-INF/applicationContext .xml "); web.xml<context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:/WEB-INF/applicationContext.xml</param-value>
        </context-param>
      

  3.   

    用一个工具类去拿,  把servletContext当做参数传进去
    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
      

  4.   


    URL url=ClassLoader.getSystemResource("");
    String path=url.toString();
    path=path.replaceAll("^(file:/)|(classes/)$", "");
    path+="applicationContext.xml";
    System.out.println(path);
    ApplicationContext context=new FileSystemXmlApplicationContext(path);