0

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

folder/myJar.jar
folder/db/connection.properties

如何在应用程序上下文中加载connection.properties ?PropertyPlaceholderConfigurer

我努力了

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="db/connection.properties"/>
</bean>

但它不会工作。

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

4

2 回答 2

10

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

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="file:db/connection.properties"/>
</bean>
于 2012-11-01T12:36:25.507 回答
-1

在 value 属性中指定文件在类路径上

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:db/connection.properties"/>
</bean>
于 2012-11-01T12:34:31.623 回答