想获取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 中的文件被调用。该怎么写才可以在通用
在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 中的文件被调用。该怎么写才可以在通用
我这样写,解析后变为
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 (系统找不到指定的路径。)
里面报错
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/WEB-INF/applicationContext.xml</param-value>
</context-param>
ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
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);