[英]Spring console app, load property file from outside of JAR
我在控制台Java應用程序中使用Spring。 我的應用程序將像這樣進行部署:
folder/myJar.jar
folder/db/connection.properties
如何在應用程序上下文中的PropertyPlaceholderConfigurer
中加載connection.properties ?
我努力了
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="db/connection.properties"/>
</bean>
但它行不通。
對於我的數據庫用戶名/密碼和其他詳細信息,我需要這種方式。
將前綴file:
添加到位置值:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="file:db/connection.properties"/>
</bean>
在value屬性中指定文件位於類路徑上
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:db/connection.properties"/>
</bean>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.