![](/img/trans.png)
[英]How do I specify a quartz property file outside of the classpath in gradle?
[英]Access a Property file outside the classpath
我需要在類路徑之外訪問屬性文件。 文件路徑將位於Windows C:\\Temp\\remote.txt
或linux /tmp/remote.txt
。 啟動應用程序服務器時,我的spring解決方案如何訪問此文件並讀取內容。
如何使用Spring PropertyPlaceholderConfigurer
或Spring Hibernate應用程序中的任何其他機制執行此操作
一個例子:
<context:property-placeholder location="file:/E:/Workspace/123.properties" />
從Spring 3.1開始,應優先使用
PropertySourcesPlaceholderConfigurer
,而不要使用此實現。 通過利用Spring 3.1中也提供的Environment
和PropertySource
機制,它更加靈活。
使用PropertySourcesPlaceholderConfigurer
可以通過以下方式從文件系統上的任何路徑加載屬性:
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
configurer.setLocations(new Resource[] {
new FileSystemResource(fileName),
});
您可以使用get資源作為流,例如:
String filePath = "C:/Temp/remote.txt";
BufferedReader input = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream(filePath)));
希望對您有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.