Spring控制台应用程序,从JAR外部加载属性文件

bra*_*ell 0 java configuration spring

我在控制台Java应用程序中使用Spring.我的应用程序将部署如下:

folder/myJar.jar
folder/db/connection.properties
Run Code Online (Sandbox Code Playgroud)

如何加载connection.propertiesPropertyPlaceholderConfigurer应用方面?

我试过了

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="db/connection.properties"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

但它不会起作用.

我需要这种方式来获取我的数据库用户名/密码和其他详细信息.

Vik*_*dor 10

将前缀添加file:到位置值:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="file:db/connection.properties"/>
</bean>
Run Code Online (Sandbox Code Playgroud)