繁体   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