Spring控制台应用程序,从JAR外部加载属性文件 [英] Spring console app, load property file from outside of JAR
本文介绍了Spring控制台应用程序,从JAR外部加载属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在控制台Java应用程序中使用Spring。
我的应用程序将部署像:
I'm using Spring in a console Java application. My application will be deployed like:
folder/myJar.jar
folder/db/connection.properties
如何在<$ c中加载 connection.properties $ c> PropertyPlaceholderConfigurer 在应用程序上下文中?
How do I load the connection.properties in a PropertyPlaceholderConfigurer
in application context?
我试过了
<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>
这篇关于Spring控制台应用程序,从JAR外部加载属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文