[英]Spring console app, load property file from outside of JAR
I'm using Spring in a console Java application. 我在控制台Java应用程序中使用Spring。 My application will be deployed like:
我的应用程序将像这样进行部署:
folder/myJar.jar
folder/db/connection.properties
How do I load the connection.properties in a PropertyPlaceholderConfigurer
in application context? 如何在应用程序上下文中的
PropertyPlaceholderConfigurer
中加载connection.properties ?
I have tried 我努力了
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="db/connection.properties"/>
</bean>
but it won't work. 但它行不通。
I need it this way for my database username/password and other details. 对于我的数据库用户名/密码和其他详细信息,我需要这种方式。
Add the prefix file:
to the location value: 将前缀
file:
添加到位置值:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="file:db/connection.properties"/>
</bean>
Specify that the file is on the classpath in the value attribute 在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.