1.加载.properties文件中的配置参数加载到PropertiesFactoryBean容器中java
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="locations">//本地资源 读取方式,用流读取资源进行加载。 <list> <value>classpath:config.properties</value> <value>classpath:redis.properties</value> </list> </property> </bean>
如此,两个properties 的属性变被放入了Spring 的PropertiesFactoryBean中redis
在此,有一点须要注意,若是在xml中须要用到刚刚配置的属性,咱们会去用${“key”}方式去取,此时须要配置“占位符“,spring
<!--在xml使用properties文件中的的配置数据时,须要用到PropertyPlaceholderConfigurer作占位符--> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="properties"> <ref bean="configProperties"/> </property> </bean>
PropertyPlaceholderConfigurer会把配置的properties解析并存放为java标准的properties,此时在xml中咱们能够经过${"key"}去取。apache
2.ui
<bean name="DatabaseConfigrationFactoryBean" class="com.shopManager.config.DatabaseConfigrationFactoryBean"> <constructor-arg ref="DatabaseConfiguration"/> </bean> <bean name="DatabaseConfiguration" class="org.apache.commons.configuration.DatabaseConfiguration"> </bean>
/** * Build a configuration from a table containing multiple configurations. * No commits are performed by the new configuration instance. * * @param datasource the datasource to connect to the database * @param table the name of the table containing the configurations * @param nameColumn the column containing the name of the configuration * @param keyColumn the column containing the keys of the configuration * @param valueColumn the column containing the values of the configuration * @param name the name of the configuration */ public DatabaseConfiguration(DataSource datasource, String table, String nameColumn, String keyColumn, String valueColumn, String name) { this(datasource, table, nameColumn, keyColumn, valueColumn, name, false); }
从它的这个构造中咱们能够发现须要传入的参数,数据源、表名、名称配置环境的名称、属性名、属性值,配置名称。(能够根据本身须要进行配置)
this