簡體   English   中英

Spring控制台應用程序,從JAR外部加載屬性文件

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM