2014-01-20 120 views
0

我有性質serverpath.properties文件,XML文件名爲search-servlet.xml的 有位置就像是/properties/serverpath.properties和/src/spring/search-servlet.xml訪問屬性文件密鑰

serverpath.properties包含以下鍵值對 wmcorelib.authentication.url = http://qae.ws.wiley.com:8001/als

現在我想用這個鍵wmcorelib.authentication.url我的XML中。

任何幫助都會很大

+0

你想在運行時或編譯時使用它嗎? – radimpe

+0

我想要編譯時間 – user2959826

+0

您可以將屬性加載到hashmap中,解析XML,然後迭代其節點。如果您發現與您的地圖匹配,請將值替換爲鍵值。這種後處理適合你嗎? –

回答

0

是search-servlet的一個bean定義文件嗎?如果是這樣的話,您可以使用spring place-holder標籤來讀取適當的文件,並用search-servlet中的鍵替換屬性文件中的值。 http://docs.spring.io/spring/docs/1.1.4/api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html

+0

是的,它是一個bean定義文件。我使用了'place-holder'標籤。 但它呈現像/classpath:/properties/myfile.properties。 在classpath之前多餘的'/'正在創建錯誤 – user2959826