我正在使用Spring-WS創建一個web服務。在我的項目中,我創建了一個Helper
類來讀取樣本響應並請求位於我的/src/main/resource
文件夾中的xml文件。如何在spring-ws中獲取應用程序上下文路徑?
當我在本地測試我的web服務應用程序時,我使用System.getProperty("user.dir")
來獲取應用程序上下文文件夾。以下是我在Helper
類中創建的一種方法,用於幫助我檢索我對資源文件夾感興趣的文件。
public static File getFileFromResources(String filename) {
System.out.println("Getting file from resource folder");
File request = null;
String curDir = System.getProperty("user.dir");
String contextpath = "C:\\src\\main\\resources\\";
request = new File(curDir + contextpath + filename);
return request;
}
然而,經過「出版」編譯WAR文件到../webapps
文件夾到的Apache Tomcat目錄中,我認識到,System.getProperty("user.dir")
不再返回我的應用程序上下文路徑。相反,它返回的Apache Tomcat的根目錄,如圖
C:\ Program Files文件\ Apache軟件基金會\ Tomcat的6.0的\ src \主\資源\ SampleClientFile
我似乎無法找到任何有關獲取我的web服務的根文件夾的信息。我看到的Spring的web應用程序的例子,我可以通過使用下面的檢索上下文路徑:
request.getSession().getServletContext().getContextPath()
但在這種情況下,我使用的是Spring的web應用程序,其中有在請求一個servlet上下文。但是Spring-WS,我的入口點是端點。我怎樣才能得到我的web服務應用程序的上下文路徑。
我期待的東西上下文路徑像
C:\ Program Files文件\ Apache軟件基金會\ Tomcat的6.0 \的webapps \ clientWebService \ WEB-INF \類
可能有人建議一個方法來實現這一點?
同意它有點笨重,但它適用於我們。 – PointZeroTwo 2015-01-21 22:25:30