【发布时间】:2018-07-21 15:27:42
【问题描述】:
我想知道是否可以从文件和数据库中加载属性,并在数据库中加载属性时使用文件中的属性。所以我想要实现的是将应用程序属性保存在数据库中,并将数据库信息保存在属性文件中。下面是我的配置,但是没有用,在读取数据库属性之前无法加载 jdbc.properties 中的值。谁可以帮我这个事?谢谢!
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:jdbc.properties</value> <!--loading properties from file first-->
</list>
</property>
<property name="properties" ref="dataBaseProperties"/> <!--loading properties from database using the properties from file-->
</bean>
<bean id="dataBaseProperties" class="common.spring.DatabaseProperties" >
<constructor-arg type="javax.sql.DataSource" ref="confDataSource"/>
<constructor-arg value="select key_s,value_s from app_conf where status>0"/>
</bean>
<bean id="confDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}"/> <!--from properties file - jdbc.properties-->
<property name="url" value="${jdbc.url}"/> <!--from properties file - jdbc.properties-->
<property name="username" value="${jdbc.username}"/> <!--from properties file - jdbc.properties-->
<property name="password" value="${jdbc.password}"/> <!--from properties file - jdbc.properties-->
</bean>
【问题讨论】:
标签: spring properties placeholder