2014-03-04 29 views
0

我曾經試圖訪問類路徑屬性&用戶定義的路徑屬性如下文件:使用Spring上下文訪問類路徑屬性和用戶定義的屬性文件?

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="locations"> 
     <list> 
      <value>Common.properties</value> 
      <value>user.home:/database.properties</value> 
     </list> 
     </property> 
     <property name="ignoreUnresolvablePlaceholders" value="true"/> 
     <property name="ignoreResourceNotFound" value="false"/> 
</bean> 

這裏Common.properties路徑是工作,但user.home:/database.properties路徑是行不通的。它顯示錯誤:使用JBoss 7

org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [user.home:/database.properties] cannot be opened because it does not exist 
(MSC service thread 1-6) at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:87) 

上午,我已經改變standalone.bat包括以下路徑:

set JAVA_OPTS=-Duser.home=file:%JBOSS_CONFIG_DIR%/database.properties 

這是正確的?如果有任何其他方式訪問自定義屬性路徑,請讓我知道。

回答

0

嘗試使用佔位符來保存系統屬性密鑰:${user.home}。此外,您還在System屬性和配置文件中複製了database.properties

+0

如何創建新的系統屬性並需要創建新的系統屬性過程? –

+0

???我想我可能會理解這個問題?通常在java命令行上設置'-Dx = y'來創建系統屬性。我看到你正在通過'JAVA_OPTS'和一個腳本來做到這一點,這很好。但是請注意,'user.home'由JVM保留,您可能無法自己設置(最好使用您自己編寫的一些密鑰,例如'config.home')。 –